瀏覽代碼

remove VAvatar and use a tool bar button instead

Le Tan 8 年之前
父節點
當前提交
b12f738edc

+ 8 - 5
src/resources/themes/v_moonlight/v_moonlight.palette

@@ -71,11 +71,10 @@ danger_pressed_bg=#AC2925
 
 [soft_defined]
 ; VAvatar.
-avatar_border_bg=#7D879B
-avatar_fg=@base_bg
-avatar_bg=@base_fg
-; The border background color of the avatar when Captain mode is triggered.
-avatar_captain_mode_border_bg=@master_bg
+; The foreground color of the avatar when Captain mode is triggered.
+avatar_captain_mode_fg=@master_fg
+; The background color of the avatar when Captain mode is triggered.
+avatar_captain_mode_bg=@master_bg
 
 ; Style of the label in Navigation mode.
 navigation_label_fg=@master_fg
@@ -177,6 +176,10 @@ pushbutton_statusbtn_hover_bg=@hover_bg
 pushbutton_statusbtn_focus_bg=@focus_bg
 pushbutton_statusbtn_pressed_bg=@pressed_bg
 
+pushbutton_avatarbtn_hover_bg=@hover_bg
+pushbutton_avatarbtn_focus_bg=@focus_bg
+pushbutton_avatarbtn_pressed_bg=@pressed_bg
+
 pushbutton_flatbtn_hover_bg=@hover_bg
 pushbutton_flatbtn_focus_bg=@focus_bg
 pushbutton_flatbtn_pressed_bg=@pressed_bg

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

@@ -441,6 +441,31 @@ QPushButton[ToolBoxActiveBtn="true"]:disabled {
     background-color: @pushbutton_disabled_bg;
 }
 
+QPushButton[AvatarBtn="true"] {
+    padding: 2px 4px 2px 4px;
+    margin: 0px;
+    border: none;
+    background-color: transparent;
+    min-width: -1;
+}
+
+QPushButton[AvatarBtn="true"]:hover {
+    background-color: @pushbutton_avatarbtn_hover_bg;
+}
+
+QPushButton[AvatarBtn="true"]:focus {
+    background-color: @pushbutton_avatarbtn_focus_bg;;
+}
+
+QPushButton[AvatarBtn="true"]:pressed {
+    background-color: @pushbutton_avatarbtn_pressed_bg;
+}
+
+QPushButton[AvatarBtn="true"]:disabled {
+    color: @pushbutton_disabled_fg;
+    background-color: @pushbutton_disabled_bg;
+}
+
 VButtonMenuItem {
     padding: 5px;
     padding-right: 30px;

+ 8 - 5
src/resources/themes/v_pure/v_pure.palette

@@ -70,11 +70,10 @@ danger_pressed_bg=#AC2925
 
 [soft_defined]
 ; VAvatar.
-avatar_border_bg=@selected_bg
-avatar_fg=@base_bg
-avatar_bg=@base_fg
-; The border background color of the avatar when Captain mode is triggered.
-avatar_captain_mode_border_bg=@master_bg
+; The foreground color of the avatar when Captain mode is triggered.
+avatar_captain_mode_fg=@master_fg
+; The background color of the avatar when Captain mode is triggered.
+avatar_captain_mode_bg=@master_bg
 
 ; Style of the label in Navigation mode.
 navigation_label_fg=@master_fg
@@ -176,6 +175,10 @@ pushbutton_statusbtn_hover_bg=@hover_bg
 pushbutton_statusbtn_focus_bg=@focus_bg
 pushbutton_statusbtn_pressed_bg=@pressed_bg
 
+pushbutton_avatarbtn_hover_bg=@hover_bg
+pushbutton_avatarbtn_focus_bg=@focus_bg
+pushbutton_avatarbtn_pressed_bg=@pressed_bg
+
 pushbutton_flatbtn_hover_bg=@hover_bg
 pushbutton_flatbtn_focus_bg=@focus_bg
 pushbutton_flatbtn_pressed_bg=@pressed_bg

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

@@ -441,6 +441,31 @@ QPushButton[ToolBoxActiveBtn="true"]:disabled {
     background-color: @pushbutton_disabled_bg;
 }
 
+QPushButton[AvatarBtn="true"] {
+    padding: 2px 4px 2px 4px;
+    margin: 0px;
+    border: none;
+    background-color: transparent;
+    min-width: -1;
+}
+
+QPushButton[AvatarBtn="true"]:hover {
+    background-color: @pushbutton_avatarbtn_hover_bg;
+}
+
+QPushButton[AvatarBtn="true"]:focus {
+    background-color: @pushbutton_avatarbtn_focus_bg;;
+}
+
+QPushButton[AvatarBtn="true"]:pressed {
+    background-color: @pushbutton_avatarbtn_pressed_bg;
+}
+
+QPushButton[AvatarBtn="true"]:disabled {
+    color: @pushbutton_disabled_fg;
+    background-color: @pushbutton_disabled_bg;
+}
+
 VButtonMenuItem {
     padding: 5px;
     padding-right: 30px;

+ 8 - 5
src/resources/themes/v_white/v_white.palette

@@ -59,11 +59,10 @@ danger_pressed_bg=#AC2925
 
 [soft_defined]
 ; VAvatar.
-avatar_border_bg=@title_bg
-avatar_fg=@base_bg
-avatar_bg=@base_fg
-; The border background color of the avatar when Captain mode is triggered.
-avatar_captain_mode_border_bg=#6C6C6C
+; The foreground color of the avatar when Captain mode is triggered.
+avatar_captain_mode_fg=@base_bg
+; The background color of the avatar when Captain mode is triggered.
+avatar_captain_mode_bg=#6C6C6C
 
 ; Style of the label in Navigation mode.
 navigation_label_fg=#4D4D4D
@@ -156,6 +155,10 @@ pushbutton_statusbtn_hover_bg=@hover_bg
 pushbutton_statusbtn_focus_bg=@focus_bg
 pushbutton_statusbtn_pressed_bg=@pressed_bg
 
+pushbutton_avatarbtn_hover_bg=@hover_bg
+pushbutton_avatarbtn_focus_bg=@focus_bg
+pushbutton_avatarbtn_pressed_bg=@pressed_bg
+
 pushbutton_flatbtn_hover_bg=@hover_bg
 pushbutton_flatbtn_focus_bg=@focus_bg
 pushbutton_flatbtn_pressed_bg=@pressed_bg

+ 25 - 0
src/resources/themes/v_white/v_white.qss

@@ -373,6 +373,31 @@ QPushButton[DangerBtn="true"]:disabled {
     background-color: @pushbutton_disabled_bg;
 }
 
+QPushButton[AvatarBtn="true"] {
+    padding: 2px 4px 2px 4px;
+    margin: 0px;
+    border: none;
+    background-color: transparent;
+    min-width: -1;
+}
+
+QPushButton[AvatarBtn="true"]:hover {
+    background-color: @pushbutton_avatarbtn_hover_bg;
+}
+
+QPushButton[AvatarBtn="true"]:focus {
+    background-color: @pushbutton_avatarbtn_focus_bg;;
+}
+
+QPushButton[AvatarBtn="true"]:pressed {
+    background-color: @pushbutton_avatarbtn_pressed_bg;
+}
+
+QPushButton[AvatarBtn="true"]:disabled {
+    color: @pushbutton_disabled_fg;
+    background-color: @pushbutton_disabled_bg;
+}
+
 VButtonMenuItem {
     padding: 5px;
     padding-right: 30px;

+ 0 - 2
src/src.pro

@@ -49,7 +49,6 @@ SOURCES += main.cpp\
     vfile.cpp \
     vnotebookselector.cpp \
     vnofocusitemdelegate.cpp \
-    vavatar.cpp \
     vmdedit.cpp \
     dialog/vfindreplacedialog.cpp \
     dialog/vsettingsdialog.cpp \
@@ -138,7 +137,6 @@ HEADERS  += vmainwindow.h \
     vfile.h \
     vnotebookselector.h \
     vnofocusitemdelegate.h \
-    vavatar.h \
     vmdedit.h \
     dialog/vfindreplacedialog.h \
     dialog/vsettingsdialog.h \

+ 0 - 117
src/vavatar.cpp

@@ -1,117 +0,0 @@
-#include "vavatar.h"
-#include <QLabel>
-#include <QPixmap>
-#include <QHBoxLayout>
-#include <QPainter>
-#include <QBrush>
-#include <QDebug>
-
-VAvatar::VAvatar(QWidget *p_parent)
-    : QWidget(p_parent, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint),
-      m_avatarText("VN"), m_diameter(48), m_borderWidth(3)
-{
-    resize(m_diameter, m_diameter);
-}
-
-void VAvatar::paintEvent(QPaintEvent * /*p_event*/)
-{
-    int diameter = width();
-    int x = diameter / 2;
-    int y = x + 1;
-
-    // Border
-    QPainterPath path;
-    path.addEllipse(QPoint(x, y), x - m_borderWidth, y - m_borderWidth);
-
-    QPainter painter(this);
-    painter.setClipPath(path);
-    painter.setClipping(true);
-    painter.setRenderHint(QPainter::Antialiasing);
-
-    if (!m_avatarPixmap.isEmpty()) {
-        drawPixmap(painter);
-    } else {
-        drawText(painter, x);
-    }
-    drawBorder(painter, path);
-}
-
-void VAvatar::drawPixmap(QPainter &p_painter)
-{
-    p_painter.drawPixmap(rect(), m_pixmap);
-}
-
-void VAvatar::drawText(QPainter &p_painter, int p_fontPixcel)
-{
-    p_painter.save();
-    QFont font = p_painter.font();
-    font.setPixelSize(p_fontPixcel);
-    p_painter.setPen(m_fgColor);
-    p_painter.setFont(font);
-    p_painter.drawText(rect(), Qt::AlignCenter, m_avatarText);
-    p_painter.restore();
-}
-
-void VAvatar::drawBorder(QPainter &p_painter, const QPainterPath &p_path)
-{
-    p_painter.save();
-    p_painter.setClipping(false);
-    QPen borderPen(m_baseColor);
-    borderPen.setWidth(m_borderWidth);
-    p_painter.setPen(borderPen);
-    p_painter.drawPath(p_path);
-    p_painter.restore();
-}
-
-void VAvatar::setDiameter(int p_diameter)
-{
-    if (m_diameter == p_diameter) {
-        return;
-    }
-    m_diameter = p_diameter;
-    resize(m_diameter, m_diameter);
-}
-
-void VAvatar::setAvatarText(const QString &p_avatarText)
-{
-    if (m_avatarText == p_avatarText) {
-        return;
-    }
-    m_avatarText = p_avatarText.left(2);
-    m_avatarPixmap.clear();
-    update();
-}
-
-void VAvatar::setAvatarPixmap(const QString &p_avatarPixmap)
-{
-    if (m_avatarPixmap == p_avatarPixmap) {
-        return;
-    }
-    m_avatarPixmap = p_avatarPixmap;
-    m_pixmap = QPixmap(m_avatarPixmap);
-    m_avatarText.clear();
-    update();
-}
-
-QSize VAvatar::sizeHint() const
-{
-    return QSize(m_diameter, m_diameter);
-}
-
-void VAvatar::setColor(const QString &p_baseColor, const QString &p_fgColor, const QString &p_bgColor)
-{
-    m_baseColor.setNamedColor(p_baseColor);
-    m_fgColor.setNamedColor(p_fgColor);
-    m_bgColor.setNamedColor(p_bgColor);
-}
-
-void VAvatar::updateBaseColor(const QString &p_baseColor)
-{
-    m_baseColor.setNamedColor(p_baseColor);
-    update();
-}
-
-QString VAvatar::getBaseColor() const
-{
-    return m_baseColor.name();
-}

+ 0 - 43
src/vavatar.h

@@ -1,43 +0,0 @@
-#ifndef VAVATAR_H
-#define VAVATAR_H
-
-#include <QWidget>
-#include <QString>
-#include <QColor>
-#include <QPixmap>
-
-class QLabel;
-
-class VAvatar : public QWidget
-{
-    Q_OBJECT
-public:
-    explicit VAvatar(QWidget *p_parent = 0);
-    void setDiameter(int p_diameter);
-    void setAvatarPixmap(const QString &p_avatarPixmap);
-    void setAvatarText(const QString &p_avatarText);
-    void setColor(const QString &p_baseColor, const QString &p_fgColor, const QString &p_bgColor);
-    void updateBaseColor(const QString &p_baseColor);
-    QSize sizeHint() const Q_DECL_OVERRIDE;
-    QString getBaseColor() const;
-
-protected:
-    void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
-
-private:
-    void drawPixmap(QPainter &p_painter);
-    void drawText(QPainter &p_painter, int p_fontPixcel);
-    void drawBorder(QPainter &p_painter, const QPainterPath &p_path);
-
-    // Draw a pixmap or characters.
-    QString m_avatarPixmap;
-    QString m_avatarText;
-    int m_diameter;
-    QColor m_baseColor;
-    QColor m_fgColor;
-    QColor m_bgColor;
-    int m_borderWidth;
-    QPixmap m_pixmap;
-};
-
-#endif // VAVATAR_H

+ 11 - 34
src/vmainwindow.cpp

@@ -12,7 +12,6 @@
 #include "veditarea.h"
 #include "voutline.h"
 #include "vnotebookselector.h"
-#include "vavatar.h"
 #include "dialog/vfindreplacedialog.h"
 #include "dialog/vsettingsdialog.h"
 #include "vcaptain.h"
@@ -83,8 +82,6 @@ VMainWindow::VMainWindow(VSingleInstanceGuard *p_guard, QWidget *p_parent)
 
     initDockWindows();
 
-    initAvatar();
-
     changePanelView(m_panelViewState);
 
     restoreStateAndGeometry();
@@ -116,13 +113,15 @@ void VMainWindow::initCaptain()
     m_captain = new VCaptain(this);
     connect(m_captain, &VCaptain::captainModeChanged,
             this, [this](bool p_captainMode) {
-                static QString normalBaseColor = m_avatar->getBaseColor();
-                static QString captainModeColor = g_palette->color("avatar_captain_mode_border_bg");
+                static QString normalStyle = m_avatarBtn->styleSheet();
+                static QString captainStyle = QString("color: %1; background: %2;")
+                                                     .arg(g_palette->color("avatar_captain_mode_fg"))
+                                                     .arg(g_palette->color("avatar_captain_mode_bg"));
 
                 if (p_captainMode) {
-                    m_avatar->updateBaseColor(captainModeColor);
+                    m_avatarBtn->setStyleSheet(captainStyle);
                 } else {
-                    m_avatar->updateBaseColor(normalBaseColor);
+                    m_avatarBtn->setStyleSheet(normalStyle);
                 }
             });
 }
@@ -589,6 +588,10 @@ void VMainWindow::initFileToolBar(QSize p_iconSize)
         fileToolBar->setIconSize(p_iconSize);
     }
 
+    m_avatarBtn = new QPushButton("VNote", this);
+    m_avatarBtn->setProperty("AvatarBtn", true);
+    m_avatarBtn->setFocusPolicy(Qt::NoFocus);
+
     newRootDirAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/create_rootdir_tb.svg"),
                                 tr("New &Root Folder"),
                                 this);
@@ -665,6 +668,7 @@ void VMainWindow::initFileToolBar(QSize p_iconSize)
     discardExitAct->setVisible(false);
     saveNoteAct->setEnabled(false);
 
+    fileToolBar->addWidget(m_avatarBtn);
     fileToolBar->addAction(newRootDirAct);
     fileToolBar->addAction(newNoteAct);
     fileToolBar->addAction(noteInfoAct);
@@ -1226,16 +1230,6 @@ void VMainWindow::initDockWindows()
     viewMenu->addAction(toggleAct);
 }
 
-void VMainWindow::initAvatar()
-{
-    m_avatar = new VAvatar(this);
-    m_avatar->setAvatarPixmap(":/resources/icons/vnote.svg");
-    m_avatar->setColor(g_palette->color("avatar_border_bg"),
-                       g_palette->color("avatar_fg"),
-                       g_palette->color("avatar_bg"));
-    m_avatar->hide();
-}
-
 void VMainWindow::importNoteFromFile()
 {
     static QString lastPath = QDir::homePath();
@@ -2117,12 +2111,6 @@ void VMainWindow::handleCurrentNotebookChanged(const VNotebook *p_notebook)
     newRootDirAct->setEnabled(p_notebook);
 }
 
-void VMainWindow::resizeEvent(QResizeEvent *event)
-{
-    repositionAvatar();
-    QMainWindow::resizeEvent(event);
-}
-
 void VMainWindow::keyPressEvent(QKeyEvent *event)
 {
     int key = event->key();
@@ -2137,17 +2125,6 @@ void VMainWindow::keyPressEvent(QKeyEvent *event)
     QMainWindow::keyPressEvent(event);
 }
 
-void VMainWindow::repositionAvatar()
-{
-    int diameter = m_mainSplitter->pos().y();
-    int x = width() - diameter - 5;
-    int y = 0;
-    qDebug() << "avatar:" << diameter << x << y;
-    m_avatar->setDiameter(diameter);
-    m_avatar->move(x, y);
-    m_avatar->show();
-}
-
 bool VMainWindow::locateFile(VFile *p_file)
 {
     bool ret = false;

+ 5 - 5
src/vmainwindow.h

@@ -26,7 +26,6 @@ class VEditArea;
 class VToolBox;
 class VOutline;
 class VNotebookSelector;
-class VAvatar;
 class VFindReplaceDialog;
 class VCaptain;
 class VVimIndicator;
@@ -165,7 +164,7 @@ private slots:
 
 protected:
     void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
-    void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
+
     void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
 
     void changeEvent(QEvent *p_event) Q_DECL_OVERRIDE;
@@ -175,7 +174,9 @@ private:
     QWidget *setupDirectoryPanel();
 
     void initToolBar();
+
     void initFileToolBar(QSize p_iconSize = QSize());
+
     void initViewToolBar(QSize p_iconSize = QSize());
 
     void initNoteToolBar(QSize p_iconSize = QSize());
@@ -191,7 +192,6 @@ private:
     void initHelpMenu();
 
     void initDockWindows();
-    void initAvatar();
     void initPredefinedColorPixmaps();
     void initRenderBackgroundMenu(QMenu *menu);
 
@@ -214,7 +214,6 @@ private:
 
     void saveStateAndGeometry();
     void restoreStateAndGeometry();
-    void repositionAvatar();
 
     // Should init VCaptain before setupUI().
     void initCaptain();
@@ -304,7 +303,6 @@ private:
     // View and manage snippets.
     VSnippetList *m_snippetList;
 
-    VAvatar *m_avatar;
     VFindReplaceDialog *m_findReplaceDialog;
     VVimIndicator *m_vimIndicator;
     VTabIndicator *m_tabIndicator;
@@ -361,6 +359,8 @@ private:
 
     QPushButton *m_headingBtn;
 
+    QPushButton *m_avatarBtn;
+
     QVector<QPixmap> predefinedColorPixmaps;
 
     // Single instance guard.