diff --git a/src/main.cpp b/src/main.cpp index 8ef268bd..3eacdf9f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,7 +17,7 @@ int main(int argc, char *argv[]) QString style = VUtils::readFileFromDisk(":/resources/vnote.qss"); if (!style.isEmpty()) { - VUtils::processStyle(style); + VUtils::processStyle(style, w.getPalette()); app.setStyleSheet(style); } diff --git a/src/resources/icons/arrow_dropdown.svg b/src/resources/icons/arrow_dropdown.svg new file mode 100644 index 00000000..d46e9629 --- /dev/null +++ b/src/resources/icons/arrow_dropdown.svg @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/src/resources/vnote.qss b/src/resources/vnote.qss index a2a860d0..c7d6afff 100644 --- a/src/resources/vnote.qss +++ b/src/resources/vnote.qss @@ -35,3 +35,44 @@ QDockWidget::close-button, QDockWidget::float-button { QDockWidget::close-button:hover, QDockWidget::float-button:hover { background-color: @hover-color; } + +/* QComboBox */ +QComboBox[OnMainWindow="true"] { + border: 1px solid grey; + background-color: @base-background; +} + +QComboBox[OnMainWindow="true"]:on { /* shift the text when the popup opens */ + padding-top: 3px; + padding-left: 4px; +} + +QComboBox[OnMainWindow="true"]::drop-down { + subcontrol-origin: padding; + subcontrol-position: top right; + width: 20px; + border: none; + background: transparent; +} + +QComboBox[OnMainWindow="true"]::down-arrow { + image: url(:/resources/icons/arrow_dropdown.svg); + width: 20px; +} + +QComboBox[OnMainWindow="true"]::down-arrow:on { /* shift the arrow when popup is open */ + top: 1px; + left: 1px; +} + +QComboBox[OnMainWindow="true"]::item { + padding-left: 20px; + border: none; + height: 20px; +} + +QComboBox[OnMainWindow="true"]::item:selected { + padding-left: 20px; + border: none; + background-color: @hover-color; +} diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index 7298abdd..ffb03ae8 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -87,14 +87,8 @@ QString VUtils::generateImageFileName(const QString &path, const QString &title, return imageName; } -void VUtils::processStyle(QString &style) +void VUtils::processStyle(QString &style, const QVector > &varMap) { - QVector > varMap; - - // Initialize varMap - addQssVarToMap(varMap, "base-color", "#4CAF50"); - addQssVarToMap(varMap, "hover-color", "#42A5F5"); - // Process style for (int i = 0; i < varMap.size(); ++i) { const QPair &map = varMap[i]; diff --git a/src/utils/vutils.h b/src/utils/vutils.h index 7e5ad932..adc6ecd0 100644 --- a/src/utils/vutils.h +++ b/src/utils/vutils.h @@ -19,7 +19,7 @@ public: static QRgb QRgbFromString(const QString &str); static QString generateImageFileName(const QString &path, const QString &title, const QString &format = "png"); - static void processStyle(QString &style); + static void processStyle(QString &style, const QVector > &varMap); static bool isMarkdown(const QString &fileName); static inline QString directoryNameFromPath(const QString& path); static QString fileNameFromPath(const QString &path); @@ -28,17 +28,8 @@ public: static void makeDirectory(const QString &path); static ClipboardOpType opTypeInClipboard(); static bool copyFile(const QString &p_srcFilePath, const QString &p_destFilePath, bool p_isCut); -private: - static inline void addQssVarToMap(QVector > &map, - const QString &key, const QString &value); }; -inline void VUtils::addQssVarToMap(QVector > &map, - const QString &key, const QString &value) -{ - map.append(QPair(key, value)); -} - inline QString VUtils::directoryNameFromPath(const QString &path) { return fileNameFromPath(path); diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index 861a20d5..e68935ca 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -19,6 +19,7 @@ VMainWindow::VMainWindow(QWidget *parent) setWindowIcon(QIcon(":/resources/icons/vnote.ico")); // Must be called before those who uses VConfigManager vnote = new VNote(); + vnote->initPalette(palette()); initPredefinedColorPixmaps(); setupUI(); initActions(); @@ -52,6 +53,7 @@ void VMainWindow::setupUI() notebookInfoBtn->setProperty("OnMainWindow", true); notebookComboBox = new QComboBox(); + notebookComboBox->setProperty("OnMainWindow", true); notebookComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); directoryTree = new VDirectoryTree(vnote); @@ -821,3 +823,8 @@ void VMainWindow::restoreStateAndGeometry() } toolDock->setVisible(vconfig.getToolsDockChecked()); } + +const QVector >& VMainWindow::getPalette() const +{ + return vnote->getPallete(); +} diff --git a/src/vmainwindow.h b/src/vmainwindow.h index 81941fab..dd11d425 100644 --- a/src/vmainwindow.h +++ b/src/vmainwindow.h @@ -2,6 +2,9 @@ #define VMAINWINDOW_H #include +#include +#include +#include class QLabel; class QComboBox; @@ -27,6 +30,7 @@ class VMainWindow : public QMainWindow public: VMainWindow(QWidget *parent = 0); ~VMainWindow(); + const QVector > &getPalette() const; private slots: void setCurNotebookIndex(int index); diff --git a/src/vnote.cpp b/src/vnote.cpp index 0d3a12c1..3cf635c3 100644 --- a/src/vnote.cpp +++ b/src/vnote.cpp @@ -21,6 +21,17 @@ VNote::VNote() : QObject() emit notebooksChanged(notebooks); } +void VNote::initPalette(QPalette palette) +{ + m_palette.clear(); + + m_palette.append(QPair("base-background", + palette.background().color().name())); + m_palette.append(QPair("base-foreground", + palette.background().color().name())); + m_palette.append(QPair("hover-color", "#42A5F5")); +} + void VNote::initTemplate() { if (templateHtml.isEmpty() || preTemplateHtml.isEmpty() diff --git a/src/vnote.h b/src/vnote.h index 7c274c1e..450b56d7 100644 --- a/src/vnote.h +++ b/src/vnote.h @@ -6,7 +6,9 @@ #include #include #include +#include #include +#include #include "vnotebook.h" enum OpenFileMode {Read = 0, Edit}; @@ -34,6 +36,9 @@ public: QString getNotebookPath(const QString &name); + inline const QVector > &getPallete() const; + void initPalette(QPalette palette); + public slots: void updateTemplate(); @@ -48,6 +53,12 @@ signals: private: QVector notebooks; QHash notebookPathHash; + QVector > m_palette; }; +inline const QVector >& VNote::getPallete() const +{ + return m_palette; +} + #endif // VNOTE_H diff --git a/src/vnote.qrc b/src/vnote.qrc index b6edbc03..8c146490 100644 --- a/src/vnote.qrc +++ b/src/vnote.qrc @@ -69,5 +69,6 @@ resources/icons/paste.svg resources/icons/dir_item.svg resources/icons/notebook_item.svg + resources/icons/arrow_dropdown.svg