mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
TagPanel: add two configs to control the behavior
- max_tag_label_length - max_num_of_tag_labels
This commit is contained in:
parent
47503fddfe
commit
2e7b2e1e5d
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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("...");
|
||||
}
|
||||
}
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user