summaryrefslogtreecommitdiff
path: root/src/moapplication.cpp
diff options
context:
space:
mode:
authorMikaƫl Capelle <capelle.mikael@gmail.com>2021-01-10 10:25:37 +0100
committerGitHub <noreply@github.com>2021-01-10 10:25:37 +0100
commit80e44a9e3ade61695b4807a3a900d2866138ecac (patch)
tree1ef9904664d8d34dba6692bbf5325aea8c199d08 /src/moapplication.cpp
parenteaec140f7c823012c09536175d8917dddcacdb7c (diff)
parent4a0ce804ea486744e5f6140a0ce4538d99e21ce3 (diff)
Merge pull request #1338 from Holt59/collapsible-separators
Collapsible separators (and refactoring).
Diffstat (limited to 'src/moapplication.cpp')
-rw-r--r--src/moapplication.cpp41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/moapplication.cpp b/src/moapplication.cpp
index fb6a7121..709bcbda 100644
--- a/src/moapplication.cpp
+++ b/src/moapplication.cpp
@@ -56,40 +56,53 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
using namespace MOBase;
using namespace MOShared;
+// style proxy that changes the appearance of drop indicators
+//
class ProxyStyle : public QProxyStyle {
public:
- ProxyStyle(QStyle *baseStyle = 0)
+ ProxyStyle(QStyle* baseStyle = 0)
: QProxyStyle(baseStyle)
{
}
- void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const {
- if(element == QStyle::PE_IndicatorItemViewItemDrop) {
+ void drawPrimitive(PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const {
+ if (element == QStyle::PE_IndicatorItemViewItemDrop) {
+
+ // 1. full-width drop indicator
+ QRect rect(option->rect);
+ if (auto* view = qobject_cast<const QTreeView*>(widget)) {
+ rect.setLeft(view->indentation());
+ rect.setRight(widget->width());
+ }
+
+ // 2. stylish drop indicator
painter->setRenderHint(QPainter::Antialiasing, true);
QColor col(option->palette.windowText().color());
QPen pen(col);
pen.setWidth(2);
col.setAlpha(50);
- QBrush brush(col);
painter->setPen(pen);
- painter->setBrush(brush);
- if(option->rect.height() == 0) {
+ painter->setBrush(QBrush(col));
+ if (rect.height() == 0) {
QPoint tri[3] = {
- option->rect.topLeft(),
- option->rect.topLeft() + QPoint(-5, 5),
- option->rect.topLeft() + QPoint(-5, -5)
+ rect.topLeft(),
+ rect.topLeft() + QPoint(-5, 5),
+ rect.topLeft() + QPoint(-5, -5)
};
painter->drawPolygon(tri, 3);
- painter->drawLine(QPoint(option->rect.topLeft().x(), option->rect.topLeft().y()), option->rect.topRight());
- } else {
- painter->drawRoundedRect(option->rect, 5, 5);
+ painter->drawLine(QPoint(rect.topLeft().x(), rect.topLeft().y()), rect.topRight());
}
- } else {
+ else {
+ painter->drawRoundedRect(rect, 5, 5);
+ }
+ }
+ else {
QProxyStyle::drawPrimitive(element, option, painter, widget);
}
}
+
};
@@ -525,8 +538,8 @@ bool MOApplication::notify(QObject* receiver, QEvent* event)
void MOApplication::updateStyle(const QString& fileName)
{
if (QStyleFactory::keys().contains(fileName)) {
- setStyle(QStyleFactory::create(fileName));
setStyleSheet("");
+ setStyle(new ProxyStyle(QStyleFactory::create(fileName)));
} else {
setStyle(new ProxyStyle(QStyleFactory::create(m_DefaultStyle)));
if (QFile::exists(fileName)) {