Browse Source

TagPanel: add two configs to control the behavior

- max_tag_label_length
- max_num_of_tag_labels
Le Tan 7 years ago
parent
commit
2e7b2e1e5d

+ 0 - 2
src/resources/themes/v_detorte/v_detorte.qss

@@ -572,8 +572,6 @@ QLabel[TagLabel="true"] {
     padding-left: $5px;
     padding-right: $5px;
     color: @tab_indicator_tag_label_fg;
-    border-top-left-radius: $10px $8px;
-    border-bottom-left-radius: $10px $8px;
     background-color: @tab_indicator_tag_label_bg;
 }
 

+ 0 - 2
src/resources/themes/v_moonlight/v_moonlight.qss

@@ -572,8 +572,6 @@ QLabel[TagLabel="true"] {
     padding-left: $5px;
     padding-right: $5px;
     color: @tab_indicator_tag_label_fg;
-    border-top-left-radius: $10px $8px;
-    border-bottom-left-radius: $10px $8px;
     background-color: @tab_indicator_tag_label_bg;
 }
 

+ 0 - 2
src/resources/themes/v_native/v_native.qss

@@ -415,8 +415,6 @@ QLabel[TagLabel="true"] {
     padding-left: $5px;
     padding-right: $5px;
     color: @tab_indicator_tag_label_fg;
-    border-top-left-radius: $10px $8px;
-    border-bottom-left-radius: $10px $8px;
     background-color: @tab_indicator_tag_label_bg;
 }
 

+ 0 - 2
src/resources/themes/v_pure/v_pure.qss

@@ -572,8 +572,6 @@ QLabel[TagLabel="true"] {
     padding-left: $5px;
     padding-right: $5px;
     color: @tab_indicator_tag_label_fg;
-    border-top-left-radius: $10px $8px;
-    border-bottom-left-radius: $10px $8px;
     background-color: @tab_indicator_tag_label_bg;
 }
 

+ 7 - 0
src/resources/vnote.ini

@@ -242,6 +242,13 @@ image_name_prefix=
 ; 2 - VerticalMode
 panel_view_state=2
 
+; Max length of the text to display in tag label
+; <= 0 indicates no limit to the length
+max_tag_label_length=10
+
+; Max number of tag labels to display
+max_num_of_tag_labels=3
+
 [export]
 ; Path of the wkhtmltopdf tool
 wkhtmltopdf=wkhtmltopdf

+ 6 - 0
src/vconfigmanager.cpp

@@ -309,6 +309,12 @@ void VConfigManager::initialize()
 
     m_panelViewState = getConfigFromSettings("global",
                                              "panel_view_state").toInt();
+
+    m_maxTagLabelLength = getConfigFromSettings("global",
+                                                "max_tag_label_length").toInt();
+
+    m_maxNumOfTagLabels = getConfigFromSettings("global",
+                                                "max_num_of_tag_labels").toInt();
 }
 
 void VConfigManager::initSettings()

+ 20 - 0
src/vconfigmanager.h

@@ -201,6 +201,10 @@ public:
     int getPanelViewState() const;
     void setPanelViewState(int p_state);
 
+    int getMaxTagLabelLength() const;
+
+    int getMaxNumOfTagLabels() const;
+
     bool getFindCaseSensitive() const;
     void setFindCaseSensitive(bool p_enabled);
 
@@ -947,6 +951,12 @@ private:
     // State of MainWindow panel view.
     int m_panelViewState;
 
+    // Max length of the tag label text.
+    int m_maxTagLabelLength;
+
+    // Max number of tag labels to display.
+    int m_maxNumOfTagLabels;
+
     // The name of the config file in each directory.
     static const QString c_dirConfigFile;
 
@@ -2475,4 +2485,14 @@ inline void VConfigManager::setPanelViewState(int p_state)
     m_panelViewState = p_state;
     setConfigToSettings("global", "panel_view_state", m_panelViewState);
 }
+
+inline int VConfigManager::getMaxTagLabelLength() const
+{
+    return m_maxTagLabelLength;
+}
+
+inline int VConfigManager::getMaxNumOfTagLabels() const
+{
+    return m_maxNumOfTagLabels;
+}
 #endif // VCONFIGMANAGER_H

+ 5 - 3
src/vtaglabel.cpp

@@ -3,8 +3,9 @@
 #include <QtWidgets>
 
 #include "utils/viconutils.h"
+#include "vconfigmanager.h"
 
-#define MAX_DISPLAY_SIZE_PER_LABEL 5
+extern VConfigManager *g_config;
 
 VTagLabel::VTagLabel(const QString &p_text,
                      bool p_useFullText,
@@ -56,8 +57,9 @@ void VTagLabel::updateLabel()
     QString tag(m_text);
 
     if (!m_useFullText) {
-        if (tag.size() > MAX_DISPLAY_SIZE_PER_LABEL) {
-            tag.resize(MAX_DISPLAY_SIZE_PER_LABEL);
+        int ml = g_config->getMaxTagLabelLength();
+        if (ml > 0 && tag.size() > ml) {
+            tag.resize(ml);
             tag += QStringLiteral("...");
         }
     }

+ 6 - 4
src/vtagpanel.cpp

@@ -10,6 +10,7 @@
 #include "vlineedit.h"
 #include "vmainwindow.h"
 #include "vnote.h"
+#include "vconfigmanager.h"
 
 extern VPalette *g_palette;
 
@@ -17,7 +18,7 @@ extern VMainWindow *g_mainWin;
 
 extern VNote *g_vnote;
 
-#define MAX_DISPLAY_LABEL 3
+extern VConfigManager *g_config;
 
 VTagPanel::VTagPanel(QWidget *parent)
     : QWidget(parent),
@@ -29,7 +30,8 @@ VTagPanel::VTagPanel(QWidget *parent)
 
 void VTagPanel::setupUI()
 {
-    for (int i = 0; i < MAX_DISPLAY_LABEL; ++i) {
+    const int maxNum = g_config->getMaxNumOfTagLabels();
+    for (int i = 0; i < maxNum; ++i) {
         VTagLabel *label = new VTagLabel(this);
         connect(label, &VTagLabel::removalRequested,
                 this, [this](const QString &p_text) {
@@ -45,7 +47,7 @@ void VTagPanel::setupUI()
             this, [this](const QString &p_text) {
                 removeTag(p_text);
 
-                if (m_file->getTags().size() <= MAX_DISPLAY_LABEL) {
+                if (m_file->getTags().size() <= g_config->getMaxNumOfTagLabels()) {
                     // Hide the more panel.
                     m_btn->hidePopupWidget();
                     m_btn->hide();
@@ -156,7 +158,7 @@ void VTagPanel::updateAllTagsPanel()
     m_tagsPanel->clear();
 
     const QStringList &tags = m_file->getTags();
-    for (int idx = MAX_DISPLAY_LABEL; idx < tags.size(); ++idx) {
+    for (int idx = g_config->getMaxNumOfTagLabels(); idx < tags.size(); ++idx) {
         m_tagsPanel->addTag(tags[idx]);
     }
 }