From 97a16f8a277c74eabdf1e0afae2ca24845f39ea3 Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Thu, 27 Feb 2014 17:41:23 +0000 Subject: [PATCH] Reduce splitter width between playqueue and views to 1 pixel. --- CMakeLists.txt | 2 +- ChangeLog | 1 + context/contextwidget.cpp | 81 ++++------------------------------ context/contextwidget.h | 3 ++ widgets/autohidingsplitter.cpp | 2 + widgets/autohidingsplitter.h | 7 ++- 6 files changed, 18 insertions(+), 78 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bfc473ec..0c0155f82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -259,7 +259,7 @@ set(CANTATA_SRCS gui/application.cpp gui/main.cpp gui/initialsettingswizard.cpp widgets/volumeslider.cpp widgets/icons.cpp widgets/genrecombo.cpp widgets/menubutton.cpp widgets/toolbutton.cpp widgets/wizardpage.cpp widgets/statuslabel.cpp widgets/searchwidget.cpp widgets/messageoverlay.cpp widgets/basicitemdelegate.cpp widgets/sizegrip.cpp widgets/sizewidget.cpp widgets/servicestatuslabel.cpp widgets/spacerwidget.cpp - widgets/songdialog.cpp widgets/stretchheaderview.cpp widgets/tableview.cpp widgets/songlabel.cpp + widgets/songdialog.cpp widgets/stretchheaderview.cpp widgets/tableview.cpp widgets/songlabel.cpp widgets/thinsplitterhandle.cpp network/networkaccessmanager.cpp network/networkproxyfactory.cpp http/httpserver.cpp devices/deviceoptions.cpp diff --git a/ChangeLog b/ChangeLog index 1ad7e2426..1947658d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ files, or removing exisint files, only ask MPD to update folders that have changed. 14. Remove space between toolbar and views, and reduce spacing elsewhere. +15. Reduce splitter width betwen playqueue and views to 1 pixel. 1.3.1 ----- diff --git a/context/contextwidget.cpp b/context/contextwidget.cpp index 0f55c4974..c86933ebb 100644 --- a/context/contextwidget.cpp +++ b/context/contextwidget.cpp @@ -38,6 +38,7 @@ #include "qjson/parser.h" #include "playqueueview.h" #include "treeview.h" +#include "thinsplitterhandle.h" #include #include #include @@ -281,85 +282,22 @@ void ViewSelector::paintEvent(QPaintEvent *ev) drawFadedLine(&p, r, palette().foreground().color()); } -static QColor splitterColor; - -class ThinSplitterHandle : public QSplitterHandle -{ -public: - ThinSplitterHandle(Qt::Orientation orientation, ThinSplitter *parent) - : QSplitterHandle(orientation, parent) - , underMouse(false) - { - setMask(QRegion(contentsRect())); - setAttribute(Qt::WA_MouseNoMask, true); - setAttribute(Qt::WA_OpaquePaintEvent, false); - setAttribute(Qt::WA_MouseTracking, true); - QAction *act=new QAction(i18n("Reset Spacing"), this); - addAction(act); - connect(act, SIGNAL(triggered(bool)), parent, SLOT(reset())); - setContextMenuPolicy(Qt::ActionsContextMenu); - size=Utils::isHighDpi() ? 4 : 2; - } - - void resizeEvent(QResizeEvent *event) - { - if (Qt::Horizontal==orientation()) { - setContentsMargins(size, 0, size, 0); - } else { - setContentsMargins(0, size, 0, size); - } - setMask(QRegion(contentsRect())); - QSplitterHandle::resizeEvent(event); - } - - void paintEvent(QPaintEvent *event) - { - if (underMouse) { - QColor col(splitterColor); - QPainter p(this); - col.setAlphaF(0.75); - p.fillRect(event->rect().adjusted(1, 0, -1, 0), col); - col.setAlphaF(0.25); - p.fillRect(event->rect(), col); - } - } - - bool event(QEvent *event) - { - switch(event->type()) { - case QEvent::Enter: - case QEvent::HoverEnter: - underMouse = true; - update(); - break; - case QEvent::ContextMenu: - case QEvent::Leave: - case QEvent::HoverLeave: - underMouse = false; - update(); - break; - default: - break; - } - - return QWidget::event(event); - } - - bool underMouse; - int size; -}; - ThinSplitter::ThinSplitter(QWidget *parent) : QSplitter(parent) { - setHandleWidth(3); setChildrenCollapsible(false); setOrientation(Qt::Horizontal); + resetAct=new QAction(i18n("Reset Spacing"), this); + connect(resetAct, SIGNAL(triggered(bool)), this, SLOT(reset())); + setHandleWidth(1); } QSplitterHandle * ThinSplitter::createHandle() { - return new ThinSplitterHandle(orientation(), this); + ThinSplitterHandle *handle=new ThinSplitterHandle(orientation(), this); + handle->addAction(resetAct); + handle->setContextMenuPolicy(Qt::ActionsContextMenu); + return handle; } void ThinSplitter::reset() @@ -412,7 +350,6 @@ ContextWidget::ContextWidget(QWidget *parent) readConfig(); setZoom(); setWide(true); - splitterColor=palette().text().color(); #ifndef SCALE_CONTEXT_BGND QDesktopWidget *dw=QApplication::desktop(); @@ -631,11 +568,9 @@ void ContextWidget::useDarkBackground(bool u) pal.setColor(QPalette::LinkVisited, linkVisited); prevLinkColor=appLinkColor; linkCol=pal.color(QPalette::Link); - splitterColor=light; } else { linkCol=appLinkColor; prevLinkColor=QColor(240, 240, 240); - splitterColor=pal.text().color(); } setPalette(pal); artist->setPal(pal, linkCol, prevLinkColor); diff --git a/context/contextwidget.h b/context/contextwidget.h index f05ffba75..068bfec7e 100644 --- a/context/contextwidget.h +++ b/context/contextwidget.h @@ -83,6 +83,9 @@ public: public Q_SLOTS: void reset(); + +private: + QAction *resetAct; }; class ContextWidget : public QWidget diff --git a/widgets/autohidingsplitter.cpp b/widgets/autohidingsplitter.cpp index 18d6de494..f5a6eb67b 100644 --- a/widgets/autohidingsplitter.cpp +++ b/widgets/autohidingsplitter.cpp @@ -73,6 +73,7 @@ AutohidingSplitter::AutohidingSplitter(Qt::Orientation orientation, QWidget *par autohideAnimation->setEasingCurve(QEasingCurve::Linear); //connect(this, SIGNAL(splitterMoved(int, int)), this, SLOT(updateAfterSplitterMoved(int, int))); setMinimumWidth(32); + setHandleWidth(1); } AutohidingSplitter::AutohidingSplitter(QWidget *parent) @@ -86,6 +87,7 @@ AutohidingSplitter::AutohidingSplitter(QWidget *parent) autohideAnimation->setEasingCurve(QEasingCurve::Linear); //connect(this, SIGNAL(splitterMoved(int, int)), this, SLOT(updateAfterSplitterMoved(int, int))); setMinimumWidth(32); + setHandleWidth(1); } AutohidingSplitter::~AutohidingSplitter() diff --git a/widgets/autohidingsplitter.h b/widgets/autohidingsplitter.h index e5db025a3..30ea64b41 100644 --- a/widgets/autohidingsplitter.h +++ b/widgets/autohidingsplitter.h @@ -26,8 +26,7 @@ #define AUTOHIDINGSPLITTER_H #include "config.h" -#include - +#include "thinsplitterhandle.h" #include #include #include @@ -38,12 +37,12 @@ Q_DECLARE_METATYPE(QList) class SplitterSizeAnimation; -class AutohidingSplitterHandle : public QSplitterHandle +class AutohidingSplitterHandle : public ThinSplitterHandle { Q_OBJECT public: - AutohidingSplitterHandle(Qt::Orientation orientation, QSplitter *parent) : QSplitterHandle(orientation, parent) { } + AutohidingSplitterHandle(Qt::Orientation orientation, QSplitter *parent) : ThinSplitterHandle(orientation, parent) { } virtual ~AutohidingSplitterHandle() { } Q_SIGNALS: