22
22
#include < theme.h>
23
23
#include < account.h>
24
24
25
- #include < QFileIconProvider>
26
- #include < QPainter>
27
25
#include < QApplication>
26
+ #include < QFileIconProvider>
28
27
#include < QMouseEvent>
28
+ #include < QPainter>
29
+ #include < QPainterPath>
30
+ #include < QRect>
29
31
#include < QStyleFactory>
30
32
31
33
inline static QFont makeAliasFont (const QFont &normalFont)
@@ -93,6 +95,9 @@ QSize FolderStatusDelegate::sizeHint(const QStyleOptionViewItem &option,
93
95
}
94
96
}
95
97
98
+ // Make sure its at least 76 Pixel high
99
+ h = std::max (h, 76 );
100
+
96
101
return {0 , h};
97
102
}
98
103
@@ -111,12 +116,77 @@ int FolderStatusDelegate::rootFolderHeightWithoutErrors(const QFontMetrics &fm,
111
116
return h;
112
117
}
113
118
119
+ QRect FolderStatusDelegate::moreRectPos (const QRect &rectIndex)
120
+ {
121
+ if (rectIndex.isValid ())
122
+ {
123
+ constexpr int buttonWidth = 88 ;
124
+ constexpr int buttonHeight = 32 ;
125
+ constexpr int margin = 16 ;
126
+
127
+ const int xMoreButton = rectIndex.right () - buttonWidth - margin;
128
+ const int yMoreButton = rectIndex.center ().y () - (buttonHeight / 2 );
129
+
130
+ return QRect (xMoreButton, yMoreButton, buttonWidth, buttonHeight);
131
+ }
132
+ return {};
133
+ }
134
+
114
135
void FolderStatusDelegate::paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
115
136
{
116
137
if (index.data (AddButton).toBool ()) {
117
138
const_cast <QStyleOptionViewItem &>(option).showDecorationSelected = false ;
118
139
}
119
140
141
+ const QModelIndex parentIndex = index.parent (); // NMC customization
142
+ {
143
+ painter->save ();
144
+
145
+ // Verhindere das Zeichnen des "Neuer Ordner"-Buttons
146
+ if (index.data (AddButton).toBool ()) {
147
+ return ;
148
+ }
149
+
150
+ const QRect leftRect (0 , option.rect .y (), option.rect .x (), option.rect .height ());
151
+
152
+ if (option.state & QStyle::State_MouseOver) {
153
+ QColor hoverColor = QApplication::palette ().color (QPalette::AlternateBase);
154
+ painter->fillRect (option.rect , hoverColor);
155
+ painter->fillRect (leftRect, hoverColor);
156
+ }
157
+
158
+ if (option.state & QStyle::State_Selected) {
159
+ // Auswahlhintergrundfarbe abrufen
160
+ const QColor selectionColor = option.palette .color (QPalette::Highlight);
161
+ painter->fillRect (leftRect, selectionColor);
162
+ }
163
+
164
+ const QTreeView* treeView = qobject_cast<const QTreeView*>(option.widget );
165
+ if (treeView) {
166
+ QIcon leftIcon;
167
+ QSize iconSize (16 , 16 );
168
+
169
+ if (!parentIndex.isValid ()) {
170
+ // Wir befinden uns im Stammverzeichnis, also Icon vergrößern
171
+ iconSize = QSize (24 , 24 );
172
+ }
173
+
174
+ if (index.isValid () && treeView->isExpanded (index)) {
175
+ // Das übergeordnete Element ist erweitert
176
+ leftIcon = QIcon (QStringLiteral (" :/client/theme/NMCIcons/collapse-down.svg" ));
177
+ } else {
178
+ // Das übergeordnete Element ist nicht erweitert
179
+ leftIcon = QIcon (QStringLiteral (" :/client/theme/NMCIcons/collapse-right.svg" ));
180
+ }
181
+
182
+ const QPoint iconPos (leftRect.width () - iconSize.width (),
183
+ leftRect.y () + leftRect.height () / 2 - iconSize.height () / 2 );
184
+ painter->drawPixmap (iconPos, leftIcon.pixmap (iconSize));
185
+ }
186
+
187
+ painter->restore ();
188
+ }
189
+
120
190
QStyledItemDelegate::paint (painter, option, index);
121
191
122
192
auto textAlign = Qt::AlignLeft;
@@ -195,7 +265,7 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
195
265
iconRect.setBottom (localPathRect.bottom ());
196
266
iconRect.setWidth (iconRect.height ());
197
267
198
- const auto nextToIcon = iconRect.right () + aliasMargin;
268
+ const auto nextToIcon = iconRect.right () + std::max ( aliasMargin, 16 ) ;
199
269
aliasRect.setLeft (nextToIcon);
200
270
localPathRect.setLeft (nextToIcon);
201
271
remotePathRect.setLeft (nextToIcon);
@@ -204,8 +274,19 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
204
274
205
275
auto optionsButtonVisualRect = optionsButtonRect (option.rect , option.direction );
206
276
207
- const auto statusPixmap = statusIcon.pixmap (iconSize, iconSize, syncEnabled ? QIcon::Normal : QIcon::Disabled);
208
- painter->drawPixmap (QStyle::visualRect (option.direction , option.rect , iconRect).left (), iconRect.top (), statusPixmap);
277
+ // NMC Customization
278
+ if (!parentIndex.isValid ()) {
279
+ QIcon nmcFolderIcon = QIcon (QLatin1String (" :/client/theme/NMCIcons/folderLogo.svg" ));
280
+ const auto nmcFolderPixmap = nmcFolderIcon.pixmap (iconSize, iconSize, QIcon::Normal);
281
+ painter->drawPixmap (QStyle::visualRect (option.direction , option.rect , iconRect).left (), iconRect.top (), nmcFolderPixmap);
282
+
283
+ const QSize statusIconSize (24 ,24 );
284
+ const auto statusPixmap = statusIcon.pixmap (statusIconSize.width (), statusIconSize.height (), syncEnabled ? QIcon::Normal : QIcon::Disabled);
285
+ painter->drawPixmap (QStyle::visualRect (option.direction , option.rect , iconRect).right () - statusIconSize.width () * 0.6 , iconRect.bottom () - statusIconSize.height () * 0.8 , statusPixmap);
286
+ } else {
287
+ const auto statusPixmap = statusIcon.pixmap (iconSize, iconSize, syncEnabled ? QIcon::Normal : QIcon::Disabled);
288
+ painter->drawPixmap (QStyle::visualRect (option.direction , option.rect , iconRect).left (), iconRect.top (), statusPixmap);
289
+ }
209
290
210
291
// only show the warning icon if the sync is running. Otherwise its
211
292
// encoded in the status icon.
@@ -292,18 +373,23 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
292
373
drawTextBox (infoTexts, QColor (0x4d , 0x4d , 0xba ));
293
374
}
294
375
376
+ // NMC customization: we need these infos already here to adjust the progress bar
377
+ const QRect currentButtonRectPos = moreRectPos (option.rect );
378
+ const int nmcWidth = currentButtonRectPos.x () - nextToIcon - 8 ; // 8 is the margin to "More" button
379
+
295
380
// Sync File Progress Bar: Show it if syncFile is not empty.
296
381
if (showProgess) {
297
382
const auto fileNameTextHeight = subFm.boundingRect (tr (" File" )).height ();
298
383
constexpr auto barHeight = 7 ; // same height as quota bar
299
384
const auto overallWidth = option.rect .right () - aliasMargin - optionsButtonVisualRect.width () - nextToIcon;
385
+ Q_UNUSED (overallWidth);
300
386
301
387
painter->save ();
302
388
303
389
// Overall Progress Bar.
304
390
const auto progressBarRect = QRect (nextToIcon,
305
391
remotePathRect.top (),
306
- overallWidth - 2 * margin ,
392
+ nmcWidth ,
307
393
barHeight);
308
394
309
395
QStyleOptionProgressBar progressBarOpt;
@@ -335,21 +421,56 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
335
421
painter->restore ();
336
422
}
337
423
338
- painter->restore ();
339
-
340
424
{
341
425
QStyleOptionToolButton btnOpt;
342
426
btnOpt.state = option.state ;
343
427
btnOpt.state &= ~(QStyle::State_Selected | QStyle::State_HasFocus);
344
428
btnOpt.state |= QStyle::State_Raised;
345
429
btnOpt.arrowType = Qt::NoArrow;
346
430
btnOpt.subControls = QStyle::SC_ToolButton;
347
- btnOpt.rect = optionsButtonVisualRect;
431
+
432
+ // NMC customization
433
+ btnOpt.rect = currentButtonRectPos;
434
+ // make sure the button is not too far away from the left border
435
+ btnOpt.rect .setRight (btnOpt.rect .x () + btnOpt.rect .width () + 4 );
436
+
437
+ // Create QPainterPath with rounded corners
438
+ QPainterPath path;
439
+ path.addRoundedRect (btnOpt.rect , 4 , 4 ); // 4 ist der Radius für die abgerundeten Ecken
440
+
441
+ // Draw border line
442
+ QPen borderPen (QColor (0 , 0 , 0 )); // Beispiel: Schwarzer Rand
443
+ borderPen.setWidth (1 );
444
+ painter->setPen (borderPen);
445
+ painter->drawPath (path);
446
+
447
+ // Fill the rectangle
448
+ painter->fillPath (path, Qt::transparent);
449
+
450
+ // Draw the icon in rectangle
348
451
btnOpt.icon = _iconMore;
349
452
const auto buttonSize = QApplication::style ()->pixelMetric (QStyle::PM_ButtonIconSize);
350
453
btnOpt.iconSize = QSize (buttonSize, buttonSize);
351
- QApplication::style ()->drawComplexControl (QStyle::CC_ToolButton, &btnOpt, painter);
454
+
455
+ // Set icon position
456
+ int iconX = btnOpt.rect .x () + btnOpt.rect .width ()/5 ;
457
+ int iconY = btnOpt.rect .y () + (btnOpt.rect .height () - btnOpt.iconSize .height ()) / 2 ;
458
+
459
+ painter->drawPixmap (iconX, iconY, btnOpt.icon .pixmap (btnOpt.iconSize ));
460
+
461
+ // Add text
462
+ const QString buttonText = QCoreApplication::translate (" " , " MORE" );
463
+ painter->setFont (btnOpt.font );
464
+ painter->setPen (option.palette .color (QPalette::ButtonText));
465
+ int textX = iconX + btnOpt.iconSize .width () + 10 ;
466
+ int textY = iconY;
467
+ int textWidth = currentButtonRectPos.x () + currentButtonRectPos.width () - textX;
468
+ int textHeight = btnOpt.fontMetrics .height ();
469
+
470
+ painter->drawText (QRect (textX, textY, textWidth, textHeight), Qt::AlignLeft | Qt::AlignVCenter, buttonText);
352
471
}
472
+
473
+ painter->restore ();
353
474
}
354
475
355
476
bool FolderStatusDelegate::editorEvent (QEvent *event, QAbstractItemModel *model,
0 commit comments