mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 06:19:52 +08:00
refine VOpenedListMenu
This commit is contained in:
parent
2798ab8ea0
commit
58b57c2a86
@ -12,7 +12,7 @@ codeblock_css_file=v_moonlight_codeblock.css
|
||||
master_fg=@edit_fg
|
||||
master_bg=#00695C
|
||||
master_light_bg=#4DB6AC
|
||||
master_drak_bg=#004D40
|
||||
master_dark_bg=#004D40
|
||||
master_focus_bg=#00796B
|
||||
master_hover_bg=#00796B
|
||||
master_pressed_bg=#004D40
|
||||
@ -139,6 +139,8 @@ toolbutton_checked_bg=@selected_bg
|
||||
toolbutton_icon_fg=@icon_fg
|
||||
toolbutton_icon_danger_fg=@danger_icon_fg
|
||||
|
||||
buttonmenuitem_decoration_text_fg=@master_light_bg
|
||||
|
||||
; Toolbox.
|
||||
toolbox_icon_fg=@master_bg
|
||||
toolbox_icon_active_fg=@master_fg
|
||||
@ -343,4 +345,4 @@ headerview_checked_bg=@selected_bg
|
||||
; ProgressBar.
|
||||
progressbar_bg=@edit_bg
|
||||
progressbar_border_bg=@border_bg
|
||||
progressbar_chunk_bg=@master_drak_bg
|
||||
progressbar_chunk_bg=@master_dark_bg
|
||||
|
@ -12,6 +12,7 @@ codeblock_css_file=v_pure_codeblock.css
|
||||
master_fg=#F5F5F5
|
||||
master_bg=#00897B
|
||||
master_light_bg=#80CBC4
|
||||
master_dark_bg=#00796B
|
||||
master_focus_bg=#009688
|
||||
master_hover_bg=#009688
|
||||
master_pressed_bg=#00796B
|
||||
@ -207,6 +208,8 @@ pushbutton_toolboxbtn_active_pressed_bg=@master_pressed_bg
|
||||
button_icon_fg=@icon_fg
|
||||
button_icon_danger_fg=@danger_icon_fg
|
||||
|
||||
buttonmenuitem_decoration_text_fg=@master_dark_bg
|
||||
|
||||
; ComboBox.
|
||||
combobox_border=@border_bg
|
||||
combobox_fg=@content_fg
|
||||
@ -220,7 +223,7 @@ combobox_focus_bg=@edit_focus_bg
|
||||
combobox_focus_border=@edit_focus_border
|
||||
combobox_item_icon_fg=@item_icon_fg
|
||||
|
||||
combobox_notebookselector_fg=@master_pressed_bg
|
||||
combobox_notebookselector_fg=@master_dark_bg
|
||||
combobox_notebookselector_bg=@combobox_bg
|
||||
combobox_notebookselector_border=@master_bg
|
||||
combobox_notebookselector_hover_fg=@master_bg
|
||||
|
@ -181,6 +181,8 @@ pushbutton_dangerbtn_pressed_bg=@danger_pressed_bg
|
||||
button_icon_fg=@icon_fg
|
||||
button_icon_danger_fg=@danger_icon_fg
|
||||
|
||||
buttonmenuitem_decoration_text_fg=#00796B
|
||||
|
||||
; ComboBox.
|
||||
combobox_border=@border_bg
|
||||
combobox_fg=@content_fg
|
||||
|
@ -9,7 +9,8 @@
|
||||
VButtonMenuItem::VButtonMenuItem(QAction *p_action, QWidget *p_parent)
|
||||
: QPushButton(p_parent),
|
||||
m_action(p_action),
|
||||
m_decorationWidth(0)
|
||||
m_decorationWidth(0),
|
||||
m_decorationFM(font())
|
||||
{
|
||||
init();
|
||||
}
|
||||
@ -17,7 +18,8 @@ VButtonMenuItem::VButtonMenuItem(QAction *p_action, QWidget *p_parent)
|
||||
VButtonMenuItem::VButtonMenuItem(QAction *p_action, const QString &p_text, QWidget *p_parent)
|
||||
: QPushButton(p_text, p_parent),
|
||||
m_action(p_action),
|
||||
m_decorationWidth(0)
|
||||
m_decorationWidth(0),
|
||||
m_decorationFM(font())
|
||||
{
|
||||
init();
|
||||
}
|
||||
@ -26,17 +28,25 @@ VButtonMenuItem::VButtonMenuItem(QAction *p_action,
|
||||
const QIcon &p_icon,
|
||||
const QString &p_text,
|
||||
const QString &p_decorationText,
|
||||
const QString &p_decorationTextFg,
|
||||
QWidget *p_parent)
|
||||
: QPushButton(p_icon, p_text, p_parent),
|
||||
m_action(p_action),
|
||||
m_decorationText(p_decorationText),
|
||||
m_decorationWidth(0)
|
||||
m_decorationTextFg(p_decorationTextFg),
|
||||
m_decorationWidth(0),
|
||||
m_decorationFM(font())
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
void VButtonMenuItem::init()
|
||||
{
|
||||
QFont ft = font();
|
||||
ft.setItalic(true);
|
||||
ft.setBold(true);
|
||||
m_decorationFM = QFontMetrics(ft);
|
||||
|
||||
connect(this, &QPushButton::clicked,
|
||||
m_action, &QAction::triggered);
|
||||
}
|
||||
@ -51,8 +61,13 @@ void VButtonMenuItem::paintEvent(QPaintEvent *p_event)
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
QFont font = painter.font();
|
||||
font.setItalic(true);
|
||||
font.setBold(true);
|
||||
painter.setFont(font);
|
||||
|
||||
QPen pen = painter.pen();
|
||||
pen.setColor(m_decorationTextFg);
|
||||
painter.setPen(pen);
|
||||
|
||||
QRect re = rect();
|
||||
re.adjust(re.width() - m_decorationWidth, 0, 0, 0);
|
||||
painter.drawText(re, Qt::AlignCenter, m_decorationText);
|
||||
@ -63,7 +78,7 @@ QSize VButtonMenuItem::sizeHint() const
|
||||
{
|
||||
QSize size = QPushButton::sizeHint();
|
||||
if (!m_decorationText.isEmpty()) {
|
||||
const_cast<VButtonMenuItem *>(this)->m_decorationWidth = 5 + fontMetrics().width(m_decorationText);
|
||||
const_cast<VButtonMenuItem *>(this)->m_decorationWidth = 10 + m_decorationFM.width(m_decorationText);
|
||||
size.rwidth() += m_decorationWidth;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
#define VBUTTONMENUITEM_H
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QColor>
|
||||
#include <QFontMetrics>
|
||||
|
||||
class QAction;
|
||||
class QPaintEvent;
|
||||
@ -19,6 +21,7 @@ public:
|
||||
const QIcon &p_icon,
|
||||
const QString &p_text,
|
||||
const QString &p_decorationText = QString(),
|
||||
const QString &p_decorationTextFg = QString(),
|
||||
QWidget *p_parent = nullptr);
|
||||
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
@ -34,8 +37,13 @@ private:
|
||||
// Decoration text drawn at the right end.
|
||||
QString m_decorationText;
|
||||
|
||||
// Decoration text foreground.
|
||||
QColor m_decorationTextFg;
|
||||
|
||||
// Width in pixels of the decoration text.
|
||||
int m_decorationWidth;
|
||||
|
||||
QFontMetrics m_decorationFM;
|
||||
};
|
||||
|
||||
#endif // VBUTTONMENUITEM_H
|
||||
|
@ -16,6 +16,9 @@
|
||||
#include "utils/vutils.h"
|
||||
#include "vbuttonmenuitem.h"
|
||||
#include "utils/vimnavigationforwidget.h"
|
||||
#include "vpalette.h"
|
||||
|
||||
extern VPalette *g_palette;
|
||||
|
||||
static const int c_cmdTime = 1 * 1000;
|
||||
|
||||
@ -126,22 +129,17 @@ void VOpenedListMenu::updateOpenedList()
|
||||
separatorText = QString("[%1] %2").arg(notebook).arg(dirName);
|
||||
}
|
||||
|
||||
// Add label as separator.
|
||||
QWidgetAction *wact = new QWidgetAction(this);
|
||||
QLabel *label = new QLabel(separatorText);
|
||||
label->setProperty("MenuSeparator", true);
|
||||
wact->setDefaultWidget(label);
|
||||
wact->setSeparator(true);
|
||||
addAction(wact);
|
||||
addSeparator();
|
||||
}
|
||||
|
||||
// Append the separator text to the end of the first item as well.
|
||||
// Append the separator text to the end of the first item.
|
||||
QWidgetAction *wact = new QWidgetAction(this);
|
||||
wact->setData(QVariant::fromValue(file));
|
||||
VButtonMenuItem *w = new VButtonMenuItem(wact,
|
||||
m_editWin->tabIcon(index),
|
||||
m_editWin->tabText(index),
|
||||
separatorText,
|
||||
g_palette->color("buttonmenuitem_decoration_text_fg"),
|
||||
this);
|
||||
w->setToolTip(generateDescription(file));
|
||||
wact->setDefaultWidget(w);
|
||||
|
Loading…
x
Reference in New Issue
Block a user