From 1a62ca15e78ecbce5289e003f111be3a6435c5bd Mon Sep 17 00:00:00 2001 From: Le Tan Date: Fri, 15 Dec 2017 20:06:02 +0800 Subject: [PATCH] attachment_list: fix editor style --- src/lineeditdelegate.cpp | 45 ++++++++++++++++++++ src/lineeditdelegate.h | 28 ++++++++++++ src/resources/themes/v_pure/v_pure.palette | 2 +- src/resources/themes/v_pure/v_pure.qss | 5 --- src/resources/themes/v_white/v_white.palette | 1 - src/resources/themes/v_white/v_white.qss | 25 +++-------- src/src.pro | 6 ++- src/vattachmentlist.cpp | 1 + src/vattachmentlist.h | 3 ++ 9 files changed, 88 insertions(+), 28 deletions(-) create mode 100644 src/lineeditdelegate.cpp create mode 100644 src/lineeditdelegate.h diff --git a/src/lineeditdelegate.cpp b/src/lineeditdelegate.cpp new file mode 100644 index 00000000..d424d255 --- /dev/null +++ b/src/lineeditdelegate.cpp @@ -0,0 +1,45 @@ +#include "lineeditdelegate.h" + +#include + + +LineEditDelegate::LineEditDelegate(QObject *p_parent) + : QStyledItemDelegate(p_parent) +{ +} + +QWidget *LineEditDelegate::createEditor(QWidget *p_parent, + const QStyleOptionViewItem &p_option, + const QModelIndex &p_index) const +{ + Q_UNUSED(p_option); + Q_UNUSED(p_index); + + QLineEdit *edit = new QLineEdit(p_parent); + return edit; +} + +void LineEditDelegate::setEditorData(QWidget *p_editor, const QModelIndex &p_index) const +{ + QString text = p_index.model()->data(p_index, Qt::EditRole).toString(); + + QLineEdit *edit = static_cast(p_editor); + edit->setText(text); +} + +void LineEditDelegate::setModelData(QWidget *p_editor, + QAbstractItemModel *p_model, + const QModelIndex &p_index) const +{ + QLineEdit *edit = static_cast(p_editor); + + p_model->setData(p_index, edit->text(), Qt::EditRole); +} + +void LineEditDelegate::updateEditorGeometry(QWidget *p_editor, + const QStyleOptionViewItem &p_option, + const QModelIndex &p_index) const +{ + Q_UNUSED(p_index); + p_editor->setGeometry(p_option.rect); +} diff --git a/src/lineeditdelegate.h b/src/lineeditdelegate.h new file mode 100644 index 00000000..018a6821 --- /dev/null +++ b/src/lineeditdelegate.h @@ -0,0 +1,28 @@ +#ifndef LINEEDITDELEGATE_H +#define LINEEDITDELEGATE_H + +#include + + +class LineEditDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + LineEditDelegate(QObject *p_parent = nullptr); + + QWidget *createEditor(QWidget *p_parent, + const QStyleOptionViewItem &p_option, + const QModelIndex &p_index) const Q_DECL_OVERRIDE; + + void setEditorData(QWidget *p_editor, const QModelIndex &p_index) const Q_DECL_OVERRIDE; + + void setModelData(QWidget *p_editor, + QAbstractItemModel *p_model, + const QModelIndex &p_index) const Q_DECL_OVERRIDE; + + void updateEditorGeometry(QWidget *p_editor, + const QStyleOptionViewItem &p_option, + const QModelIndex &p_index) const Q_DECL_OVERRIDE; +}; + +#endif // LINEEDITDELEGATE_H diff --git a/src/resources/themes/v_pure/v_pure.palette b/src/resources/themes/v_pure/v_pure.palette index f08bb0d0..af29bb0c 100644 --- a/src/resources/themes/v_pure/v_pure.palette +++ b/src/resources/themes/v_pure/v_pure.palette @@ -214,7 +214,7 @@ combobox_focus_bg=@edit_focus_bg combobox_focus_border=@edit_focus_border combobox_item_icon_fg=@item_icon_fg -combobox_notebookselector_fg=@master_bg +combobox_notebookselector_fg=@master_pressed_bg combobox_notebookselector_bg=@combobox_bg combobox_notebookselector_border=@master_bg combobox_notebookselector_hover_fg=@master_bg diff --git a/src/resources/themes/v_pure/v_pure.qss b/src/resources/themes/v_pure/v_pure.qss index 4f85f041..66f4d366 100644 --- a/src/resources/themes/v_pure/v_pure.qss +++ b/src/resources/themes/v_pure/v_pure.qss @@ -671,11 +671,6 @@ QLineEdit[VimCommandLine="true"] { color: @lineedit_fg; background: @lineedit_bg; } - -QAbstractItemView QLineEdit { - padding: 0px; - margin: 0px; -} /* End QLineEdit */ /* QPlainTextEdit QTextEdit */ diff --git a/src/resources/themes/v_white/v_white.palette b/src/resources/themes/v_white/v_white.palette index da233c1b..687555ec 100644 --- a/src/resources/themes/v_white/v_white.palette +++ b/src/resources/themes/v_white/v_white.palette @@ -258,7 +258,6 @@ listview_item_selected_inactive_bg=@inactive_bg ; Splitter. splitter_handle_bg=@title_bg -splitter_mainsplitter_border=@title_bg ; StatusBar. statusbar_fg=@main_fg diff --git a/src/resources/themes/v_white/v_white.qss b/src/resources/themes/v_white/v_white.qss index 20232692..88af5b6f 100644 --- a/src/resources/themes/v_white/v_white.qss +++ b/src/resources/themes/v_white/v_white.qss @@ -583,11 +583,6 @@ QLineEdit[VimCommandLine="true"] { color: @lineedit_fg; background: @lineedit_bg; } - -QAbstractItemView QLineEdit { - padding: 0px; - margin: 0px; -} /* End QLineEdit */ /* QTabWidget */ @@ -605,27 +600,23 @@ QTabWidget::pane { QTabBar::tab { color: @tabbar_fg; background: @tabbar_bg; - border: 1px solid @tabbar_border; - border-bottom: none; + border: none; + border-right: 1px solid @tabbar_border; padding: 2px; } QTabBar::tab:selected { color: @tabbar_selected_fg; background: @tabbar_selected_bg; - border: 1px solid @tabbar_selected_border; - border-bottom: none; + border: none; + border-right: 1px solid @tabbar_border; } QTabBar::tab:hover { color: @tabbar_hover_fg; background: @tabbar_hover_bg; - border: 1px solid @tabbar_hover_border; - border-bottom: none; -} - -QTabBar::tab:!selected { - margin-top: 2px; /* make non-selected tabs look smaller */ + border: none; + border-right: 1px solid @tabbar_border; } QTabBar::close-button { @@ -793,10 +784,6 @@ QSplitter::handle:vertical { QSplitter::handle:horizontal { width: 2px; } - -QSplitter#MainSplitter { - border-top: 2px solid @splitter_mainsplitter_border; -} /* End QSplitter */ /* QStatusBar */ diff --git a/src/src.pro b/src/src.pro index 49554fe3..1996e1fb 100644 --- a/src/src.pro +++ b/src/src.pro @@ -101,7 +101,8 @@ SOURCES += main.cpp\ utils/vclipboardutils.cpp \ vpalette.cpp \ vbuttonmenuitem.cpp \ - utils/viconutils.cpp + utils/viconutils.cpp \ + lineeditdelegate.cpp HEADERS += vmainwindow.h \ vdirectorytree.h \ @@ -189,7 +190,8 @@ HEADERS += vmainwindow.h \ utils/vclipboardutils.h \ vpalette.h \ vbuttonmenuitem.h \ - utils/viconutils.h + utils/viconutils.h \ + lineeditdelegate.h RESOURCES += \ vnote.qrc \ diff --git a/src/vattachmentlist.cpp b/src/vattachmentlist.cpp index 376b4559..63272310 100644 --- a/src/vattachmentlist.cpp +++ b/src/vattachmentlist.cpp @@ -102,6 +102,7 @@ void VAttachmentList::setupUI() m_attachmentList->setSelectionMode(QAbstractItemView::ExtendedSelection); m_attachmentList->setEditTriggers(QAbstractItemView::SelectedClicked); m_attachmentList->setAttribute(Qt::WA_MacShowFocusRect, false); + m_attachmentList->setItemDelegate(&m_listDelegate); connect(m_attachmentList, &QListWidget::customContextMenuRequested, this, &VAttachmentList::handleContextMenuRequested); connect(m_attachmentList, &QListWidget::itemActivated, diff --git a/src/vattachmentlist.h b/src/vattachmentlist.h index 52a45964..45c94a93 100644 --- a/src/vattachmentlist.h +++ b/src/vattachmentlist.h @@ -6,6 +6,7 @@ #include #include "vnotefile.h" #include "vbuttonwithwidget.h" +#include "lineeditdelegate.h" class QPushButton; class QListWidget; @@ -14,6 +15,7 @@ class QLabel; class VNoteFile; class QAction; + class VAttachmentList : public QWidget, public VButtonPopupWidget { Q_OBJECT @@ -70,6 +72,7 @@ private: QPushButton *m_locateBtn; QLabel *m_numLabel; + LineEditDelegate m_listDelegate; QListWidget *m_attachmentList; QAction *m_openAct;