refine VOpenedListMenu

This commit is contained in:
Le Tan 2017-12-26 19:27:10 +08:00
parent 2798ab8ea0
commit 58b57c2a86
6 changed files with 43 additions and 15 deletions

View File

@ -12,7 +12,7 @@ codeblock_css_file=v_moonlight_codeblock.css
master_fg=@edit_fg master_fg=@edit_fg
master_bg=#00695C master_bg=#00695C
master_light_bg=#4DB6AC master_light_bg=#4DB6AC
master_drak_bg=#004D40 master_dark_bg=#004D40
master_focus_bg=#00796B master_focus_bg=#00796B
master_hover_bg=#00796B master_hover_bg=#00796B
master_pressed_bg=#004D40 master_pressed_bg=#004D40
@ -139,6 +139,8 @@ toolbutton_checked_bg=@selected_bg
toolbutton_icon_fg=@icon_fg toolbutton_icon_fg=@icon_fg
toolbutton_icon_danger_fg=@danger_icon_fg toolbutton_icon_danger_fg=@danger_icon_fg
buttonmenuitem_decoration_text_fg=@master_light_bg
; Toolbox. ; Toolbox.
toolbox_icon_fg=@master_bg toolbox_icon_fg=@master_bg
toolbox_icon_active_fg=@master_fg toolbox_icon_active_fg=@master_fg
@ -343,4 +345,4 @@ headerview_checked_bg=@selected_bg
; ProgressBar. ; ProgressBar.
progressbar_bg=@edit_bg progressbar_bg=@edit_bg
progressbar_border_bg=@border_bg progressbar_border_bg=@border_bg
progressbar_chunk_bg=@master_drak_bg progressbar_chunk_bg=@master_dark_bg

View File

@ -12,6 +12,7 @@ codeblock_css_file=v_pure_codeblock.css
master_fg=#F5F5F5 master_fg=#F5F5F5
master_bg=#00897B master_bg=#00897B
master_light_bg=#80CBC4 master_light_bg=#80CBC4
master_dark_bg=#00796B
master_focus_bg=#009688 master_focus_bg=#009688
master_hover_bg=#009688 master_hover_bg=#009688
master_pressed_bg=#00796B master_pressed_bg=#00796B
@ -207,6 +208,8 @@ pushbutton_toolboxbtn_active_pressed_bg=@master_pressed_bg
button_icon_fg=@icon_fg button_icon_fg=@icon_fg
button_icon_danger_fg=@danger_icon_fg button_icon_danger_fg=@danger_icon_fg
buttonmenuitem_decoration_text_fg=@master_dark_bg
; ComboBox. ; ComboBox.
combobox_border=@border_bg combobox_border=@border_bg
combobox_fg=@content_fg combobox_fg=@content_fg
@ -220,7 +223,7 @@ combobox_focus_bg=@edit_focus_bg
combobox_focus_border=@edit_focus_border combobox_focus_border=@edit_focus_border
combobox_item_icon_fg=@item_icon_fg 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_bg=@combobox_bg
combobox_notebookselector_border=@master_bg combobox_notebookselector_border=@master_bg
combobox_notebookselector_hover_fg=@master_bg combobox_notebookselector_hover_fg=@master_bg

View File

@ -181,6 +181,8 @@ pushbutton_dangerbtn_pressed_bg=@danger_pressed_bg
button_icon_fg=@icon_fg button_icon_fg=@icon_fg
button_icon_danger_fg=@danger_icon_fg button_icon_danger_fg=@danger_icon_fg
buttonmenuitem_decoration_text_fg=#00796B
; ComboBox. ; ComboBox.
combobox_border=@border_bg combobox_border=@border_bg
combobox_fg=@content_fg combobox_fg=@content_fg

View File

@ -9,7 +9,8 @@
VButtonMenuItem::VButtonMenuItem(QAction *p_action, QWidget *p_parent) VButtonMenuItem::VButtonMenuItem(QAction *p_action, QWidget *p_parent)
: QPushButton(p_parent), : QPushButton(p_parent),
m_action(p_action), m_action(p_action),
m_decorationWidth(0) m_decorationWidth(0),
m_decorationFM(font())
{ {
init(); 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) VButtonMenuItem::VButtonMenuItem(QAction *p_action, const QString &p_text, QWidget *p_parent)
: QPushButton(p_text, p_parent), : QPushButton(p_text, p_parent),
m_action(p_action), m_action(p_action),
m_decorationWidth(0) m_decorationWidth(0),
m_decorationFM(font())
{ {
init(); init();
} }
@ -26,17 +28,25 @@ VButtonMenuItem::VButtonMenuItem(QAction *p_action,
const QIcon &p_icon, const QIcon &p_icon,
const QString &p_text, const QString &p_text,
const QString &p_decorationText, const QString &p_decorationText,
const QString &p_decorationTextFg,
QWidget *p_parent) QWidget *p_parent)
: QPushButton(p_icon, p_text, p_parent), : QPushButton(p_icon, p_text, p_parent),
m_action(p_action), m_action(p_action),
m_decorationText(p_decorationText), m_decorationText(p_decorationText),
m_decorationWidth(0) m_decorationTextFg(p_decorationTextFg),
m_decorationWidth(0),
m_decorationFM(font())
{ {
init(); init();
} }
void VButtonMenuItem::init() void VButtonMenuItem::init()
{ {
QFont ft = font();
ft.setItalic(true);
ft.setBold(true);
m_decorationFM = QFontMetrics(ft);
connect(this, &QPushButton::clicked, connect(this, &QPushButton::clicked,
m_action, &QAction::triggered); m_action, &QAction::triggered);
} }
@ -51,8 +61,13 @@ void VButtonMenuItem::paintEvent(QPaintEvent *p_event)
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
QFont font = painter.font(); QFont font = painter.font();
font.setItalic(true); font.setItalic(true);
font.setBold(true);
painter.setFont(font); painter.setFont(font);
QPen pen = painter.pen();
pen.setColor(m_decorationTextFg);
painter.setPen(pen);
QRect re = rect(); QRect re = rect();
re.adjust(re.width() - m_decorationWidth, 0, 0, 0); re.adjust(re.width() - m_decorationWidth, 0, 0, 0);
painter.drawText(re, Qt::AlignCenter, m_decorationText); painter.drawText(re, Qt::AlignCenter, m_decorationText);
@ -63,7 +78,7 @@ QSize VButtonMenuItem::sizeHint() const
{ {
QSize size = QPushButton::sizeHint(); QSize size = QPushButton::sizeHint();
if (!m_decorationText.isEmpty()) { 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; size.rwidth() += m_decorationWidth;
} }

View File

@ -2,6 +2,8 @@
#define VBUTTONMENUITEM_H #define VBUTTONMENUITEM_H
#include <QPushButton> #include <QPushButton>
#include <QColor>
#include <QFontMetrics>
class QAction; class QAction;
class QPaintEvent; class QPaintEvent;
@ -19,6 +21,7 @@ public:
const QIcon &p_icon, const QIcon &p_icon,
const QString &p_text, const QString &p_text,
const QString &p_decorationText = QString(), const QString &p_decorationText = QString(),
const QString &p_decorationTextFg = QString(),
QWidget *p_parent = nullptr); QWidget *p_parent = nullptr);
QSize sizeHint() const Q_DECL_OVERRIDE; QSize sizeHint() const Q_DECL_OVERRIDE;
@ -34,8 +37,13 @@ private:
// Decoration text drawn at the right end. // Decoration text drawn at the right end.
QString m_decorationText; QString m_decorationText;
// Decoration text foreground.
QColor m_decorationTextFg;
// Width in pixels of the decoration text. // Width in pixels of the decoration text.
int m_decorationWidth; int m_decorationWidth;
QFontMetrics m_decorationFM;
}; };
#endif // VBUTTONMENUITEM_H #endif // VBUTTONMENUITEM_H

View File

@ -16,6 +16,9 @@
#include "utils/vutils.h" #include "utils/vutils.h"
#include "vbuttonmenuitem.h" #include "vbuttonmenuitem.h"
#include "utils/vimnavigationforwidget.h" #include "utils/vimnavigationforwidget.h"
#include "vpalette.h"
extern VPalette *g_palette;
static const int c_cmdTime = 1 * 1000; static const int c_cmdTime = 1 * 1000;
@ -126,22 +129,17 @@ void VOpenedListMenu::updateOpenedList()
separatorText = QString("[%1] %2").arg(notebook).arg(dirName); separatorText = QString("[%1] %2").arg(notebook).arg(dirName);
} }
// Add label as separator. addSeparator();
QWidgetAction *wact = new QWidgetAction(this);
QLabel *label = new QLabel(separatorText);
label->setProperty("MenuSeparator", true);
wact->setDefaultWidget(label);
wact->setSeparator(true);
addAction(wact);
} }
// 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); QWidgetAction *wact = new QWidgetAction(this);
wact->setData(QVariant::fromValue(file)); wact->setData(QVariant::fromValue(file));
VButtonMenuItem *w = new VButtonMenuItem(wact, VButtonMenuItem *w = new VButtonMenuItem(wact,
m_editWin->tabIcon(index), m_editWin->tabIcon(index),
m_editWin->tabText(index), m_editWin->tabText(index),
separatorText, separatorText,
g_palette->color("buttonmenuitem_decoration_text_fg"),
this); this);
w->setToolTip(generateDescription(file)); w->setToolTip(generateDescription(file));
wact->setDefaultWidget(w); wact->setDefaultWidget(w);