Skip to content

Commit eb7f17b

Browse files
memuratsgithub-actions
authored andcommitted
folderview settings dialog changes
1 parent 97cfbea commit eb7f17b

8 files changed

Lines changed: 225 additions & 63 deletions

src/gui/accountsettings.cpp

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class MouseCursorChanger : public QObject
160160
const auto index = folderList->indexAt(pos);
161161
if (model->classify(index) == FolderStatusModel::RootFolder &&
162162
(FolderStatusDelegate::errorsListRect(folderList->visualRect(index)).contains(pos) ||
163-
FolderStatusDelegate::optionsButtonRect(folderList->visualRect(index),folderList->layoutDirection()).contains(pos))) {
163+
FolderStatusDelegate::moreRectPos(folderList->visualRect(index)).contains(pos))) {
164164
shape = Qt::PointingHandCursor;
165165
}
166166
folderList->setCursor(shape);
@@ -626,8 +626,9 @@ void AccountSettings::slotSubfolderContextMenuRequested(const QModelIndex& index
626626
{
627627
Q_UNUSED(pos);
628628

629-
QMenu menu;
630-
auto ac = menu.addAction(tr("Open folder"));
629+
auto menu = new QMenu(this);
630+
menu->setAttribute(Qt::WA_DeleteOnClose);
631+
auto ac = menu->addAction(tr("Open folder"));
631632
connect(ac, &QAction::triggered, this, &AccountSettings::slotOpenCurrentLocalSubFolder);
632633

633634
const auto fileName = _model->data(index, FolderStatusDelegate::FolderPathRole).toString();
@@ -646,24 +647,21 @@ void AccountSettings::slotSubfolderContextMenuRequested(const QModelIndex& index
646647
const auto isExternal = info->_isExternal;
647648

648649
if (!isEncrypted && !isParentEncrypted && !isExternal && isTopFolder) {
649-
ac = menu.addAction(tr("Encrypt"));
650+
ac = menu->addAction(tr("Encrypt"));
650651
connect(ac, &QAction::triggered, [this, info] { slotMarkSubfolderEncrypted(info); });
651652
} else {
652653
// Ignore decrypting for now since it only works with an empty folder
653654
// connect(ac, &QAction::triggered, [this, &info] { slotMarkSubfolderDecrypted(info); });
654655
}
655656
}
656657

657-
ac = menu.addAction(tr("Edit Ignored Files"));
658-
connect(ac, &QAction::triggered, this, &AccountSettings::slotEditCurrentLocalIgnoredFiles);
659-
660-
ac = menu.addAction(tr("Create new folder"));
658+
ac = menu->addAction(tr("Create new folder"));
661659
connect(ac, &QAction::triggered, this, &AccountSettings::slotOpenMakeFolderDialog);
662660
ac->setEnabled(QFile::exists(fileName));
663661

664662
const auto folder = info->_folder;
665663
if (folder && folder->virtualFilesEnabled()) {
666-
auto availabilityMenu = menu.addMenu(tr("Availability"));
664+
auto availabilityMenu = menu->addMenu(tr("Availability"));
667665

668666
// Has '/' suffix convention for paths here but VFS and
669667
// sync engine expects no such suffix
@@ -686,7 +684,23 @@ void AccountSettings::slotSubfolderContextMenuRequested(const QModelIndex& index
686684
connect(ac, &QAction::triggered, this, [this, folder, path] { slotSetSubFolderAvailability(folder, path, PinState::OnlineOnly); });
687685
}
688686

689-
menu.exec(QCursor::pos());
687+
const auto highlightColor = palette().highlight().color();
688+
menu->setStyleSheet(QString(R"(
689+
QMenu {
690+
border: 1px solid black;
691+
border-radius: 4px;
692+
padding: 6px;
693+
}
694+
QMenu::item {
695+
padding: 8px;
696+
}
697+
QMenu::item:selected,
698+
QMenu::item:hover {
699+
background-color: %1;
700+
}
701+
)").arg(highlightColor.name(QColor::HexRgb)));
702+
703+
menu->popup(QCursor::pos());
690704
}
691705

692706
void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
@@ -717,16 +731,13 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
717731
return;
718732
}
719733

720-
const auto menu = new QMenu(treeView);
734+
auto menu = new QMenu(treeView);
721735

722736
menu->setAttribute(Qt::WA_DeleteOnClose);
723737

724738
auto ac = menu->addAction(tr("Open folder"));
725739
connect(ac, &QAction::triggered, this, &AccountSettings::slotOpenCurrentFolder);
726740

727-
ac = menu->addAction(tr("Edit Ignored Files"));
728-
connect(ac, &QAction::triggered, this, &AccountSettings::slotEditCurrentIgnoredFiles);
729-
730741
ac = menu->addAction(tr("Create new folder"));
731742
connect(ac, &QAction::triggered, this, &AccountSettings::slotOpenMakeFolderDialog);
732743
ac->setEnabled(QFile::exists(folder->path()));
@@ -782,40 +793,33 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
782793
}
783794
}
784795

796+
const auto highlightColor = palette().highlight().color();
785797

786-
menu->popup(treeView->mapToGlobal(pos));
798+
menu->setStyleSheet(QString(R"(
799+
QMenu {
800+
border: 1px solid black;
801+
border-radius: 4px;
802+
padding: 6px;
803+
}
804+
QMenu::item {
805+
padding: 8px;
806+
}
807+
QMenu::item:selected,
808+
QMenu::item:hover {
809+
background-color: %1;
810+
}
811+
)").arg(highlightColor.name(QColor::HexRgb)));
812+
813+
menu->popup(treeView->viewport()->mapToGlobal(pos));
787814
}
788815

789816
void AccountSettings::slotFolderListClicked(const QModelIndex &indx)
790817
{
791-
if (indx.data(FolderStatusDelegate::AddButton).toBool()) {
792-
// "Add Folder Sync Connection"
793-
const auto treeView = _ui->_folderList;
794-
const auto pos = treeView->mapFromGlobal(QCursor::pos());
795-
QStyleOptionViewItem opt;
796-
opt.initFrom(treeView);
797-
const auto btnRect = treeView->visualRect(indx);
798-
const auto btnSize = treeView->itemDelegateForIndex(indx)->sizeHint(opt, indx);
799-
const auto actual = QStyle::visualRect(opt.direction, btnRect, QRect(btnRect.topLeft(), btnSize));
800-
if (!actual.contains(pos)) {
801-
return;
802-
}
803-
804-
if (indx.flags() & Qt::ItemIsEnabled) {
805-
slotAddFolder();
806-
} else {
807-
QToolTip::showText(
808-
QCursor::pos(),
809-
_model->data(indx, Qt::ToolTipRole).toString(),
810-
this);
811-
}
812-
return;
813-
}
814818
if (_model->classify(indx) == FolderStatusModel::RootFolder) {
815819
// tries to find if we clicked on the '...' button.
816820
const auto treeView = _ui->_folderList;
817821
const auto pos = treeView->mapFromGlobal(QCursor::pos());
818-
if (FolderStatusDelegate::optionsButtonRect(treeView->visualRect(indx), layoutDirection()).contains(pos)) {
822+
if (FolderStatusDelegate::moreRectPos(treeView->visualRect(indx)).contains(pos)) {
819823
slotCustomContextMenuRequested(pos);
820824
return;
821825
}

src/gui/accountsetupcommandlinemanager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,6 @@ void AccountSetupCommandLineManager::setupAccountFromCommandLine()
105105
_serverUrl.clear();
106106
_remoteDirPath.clear();
107107
_localDirPath.clear();
108-
_isVfsEnabled = true;
108+
_isVfsEnabled = false;
109109
}
110110
}

src/gui/folderstatusdelegate.cpp

Lines changed: 128 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include <QFileIconProvider>
1616
#include <QPainter>
17+
#include <QPainterPath>
18+
#include <QRect>
1719
#include <QApplication>
1820
#include <QMouseEvent>
1921
#include <QStyleFactory>
@@ -105,9 +107,28 @@ QSize FolderStatusDelegate::sizeHint(const QStyleOptionViewItem &option,
105107
h += margin + btnSize.height();
106108
}
107109

110+
// Make sure its at least 76 Pixel high
111+
h = std::max(h, 76);
112+
108113
return {0, h};
109114
}
110115

116+
QRect FolderStatusDelegate::moreRectPos(const QRect &rectIndex)
117+
{
118+
if (rectIndex.isValid())
119+
{
120+
constexpr int buttonWidth = 88;
121+
constexpr int buttonHeight = 32;
122+
constexpr int margin = 16;
123+
124+
const int xMoreButton = rectIndex.right() - buttonWidth - margin;
125+
const int yMoreButton = rectIndex.center().y() - (buttonHeight / 2);
126+
127+
return QRect(xMoreButton, yMoreButton, buttonWidth, buttonHeight);
128+
}
129+
return {};
130+
}
131+
111132
int FolderStatusDelegate::rootFolderHeightWithoutErrors(const QFontMetrics &fm, const QFontMetrics &aliasFm)
112133
{
113134
const int aliasMargin = aliasFm.height() / 2;
@@ -129,6 +150,56 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
129150
const_cast<QStyleOptionViewItem &>(option).showDecorationSelected = false;
130151
}
131152

153+
const QModelIndex parentIndex = index.parent(); // NMC customization
154+
{
155+
painter->save();
156+
157+
// Verhindere das Zeichnen des "Neuer Ordner"-Buttons
158+
if (index.data(AddButton).toBool()) {
159+
return;
160+
}
161+
162+
const QRect leftRect(0, option.rect.y(), option.rect.x(), option.rect.height());
163+
164+
if (option.state & QStyle::State_MouseOver) {
165+
QColor hoverColor = QApplication::palette().color(QPalette::Mid);
166+
painter->fillRect(option.rect, hoverColor);
167+
painter->fillRect(leftRect, hoverColor);
168+
}
169+
170+
if (option.state & QStyle::State_Selected) {
171+
// Auswahlhintergrundfarbe abrufen
172+
const QColor selectionColor = option.palette.color(QPalette::Highlight);
173+
painter->fillRect(option.rect, selectionColor);
174+
painter->fillRect(leftRect, selectionColor);
175+
}
176+
177+
const QTreeView* treeView = qobject_cast<const QTreeView*>(option.widget);
178+
if (treeView) {
179+
QIcon leftIcon;
180+
QSize iconSize(16, 16);
181+
182+
if (!parentIndex.isValid()) {
183+
// Wir befinden uns im Stammverzeichnis, also Icon vergrößern
184+
iconSize = QSize(24, 24);
185+
}
186+
187+
if (index.isValid() && treeView->isExpanded(index)) {
188+
// Das übergeordnete Element ist erweitert
189+
leftIcon = QIcon(Theme::createColorAwareIcon(QStringLiteral(":/client/theme/NMCIcons/collapse-down.svg")));
190+
} else {
191+
// Das übergeordnete Element ist nicht erweitert
192+
leftIcon = QIcon(Theme::createColorAwareIcon(QStringLiteral(":/client/theme/NMCIcons/collapse-right.svg")));
193+
}
194+
195+
const QPoint iconPos(leftRect.width() - iconSize.width(),
196+
leftRect.y() + leftRect.height() / 2 - iconSize.height() / 2);
197+
painter->drawPixmap(iconPos, leftIcon.pixmap(iconSize));
198+
}
199+
200+
painter->restore();
201+
}
202+
132203
QStyledItemDelegate::paint(painter, option, index);
133204

134205
auto textAlign = Qt::AlignLeft;
@@ -223,12 +294,19 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
223294

224295
auto optionsButtonVisualRect = optionsButtonRect(option.rect, option.direction);
225296

226-
statusIcon.paint(
227-
painter,
228-
QStyle::visualRect(option.direction, option.rect, iconRect),
229-
Qt::AlignCenter,
230-
syncEnabled ? QIcon::Normal : QIcon::Disabled
231-
);
297+
// NMC Customization
298+
if (!parentIndex.isValid()) {
299+
QIcon nmcFolderIcon = QIcon(QLatin1String(":/client/theme/NMCIcons/folderLogo.svg"));
300+
const auto nmcFolderPixmap = nmcFolderIcon.pixmap(iconSize, iconSize, QIcon::Normal);
301+
painter->drawPixmap(QStyle::visualRect(option.direction, option.rect, iconRect).left(), iconRect.top(), nmcFolderPixmap);
302+
303+
const QSize statusIconSize(24,24);
304+
const auto statusPixmap = statusIcon.pixmap(statusIconSize.width(), statusIconSize.height(), syncEnabled ? QIcon::Normal : QIcon::Disabled);
305+
painter->drawPixmap(QStyle::visualRect(option.direction, option.rect, iconRect).right() - statusIconSize.width() * 0.6, iconRect.bottom() - statusIconSize.height() * 0.8, statusPixmap);
306+
} else {
307+
const auto statusPixmap = statusIcon.pixmap(iconSize, iconSize, syncEnabled ? QIcon::Normal : QIcon::Disabled);
308+
painter->drawPixmap(QStyle::visualRect(option.direction, option.rect, iconRect).left(), iconRect.top(), statusPixmap);
309+
}
232310

233311
auto palette = option.palette;
234312

@@ -341,18 +419,23 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
341419
drawTextBox(infoTexts, QColor(0x4d, 0x4d, 0xba));
342420
}
343421

422+
// NMC customization: we need these infos already here to adjust the progress bar
423+
const QRect currentButtonRectPos = moreRectPos(option.rect);
424+
const int nmcWidth = currentButtonRectPos.x() - nextToIcon - 8; // 8 is the margin to "More" button
425+
344426
// Sync File Progress Bar: Show it if syncFile is not empty.
345427
if (showProgess) {
346428
const auto fileNameTextHeight = subFm.boundingRect(tr("File")).height();
347429
constexpr auto barHeight = 7; // same height as quota bar
348430
const auto overallWidth = option.rect.right() - aliasMargin - optionsButtonVisualRect.width() - nextToIcon;
431+
Q_UNUSED(overallWidth);
349432

350433
painter->save();
351434

352435
// Overall Progress Bar.
353436
const auto progressBarRect = QRect(nextToIcon,
354437
remotePathRect.top(),
355-
overallWidth - 2 * margin,
438+
nmcWidth,
356439
barHeight);
357440

358441
QStyleOptionProgressBar progressBarOpt;
@@ -384,21 +467,55 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
384467
painter->restore();
385468
}
386469

387-
painter->restore();
388-
389470
{
390471
QStyleOptionToolButton btnOpt;
391472
btnOpt.state = option.state;
392473
btnOpt.state &= ~(QStyle::State_Selected | QStyle::State_HasFocus);
393474
btnOpt.state |= QStyle::State_Raised;
394475
btnOpt.arrowType = Qt::NoArrow;
395476
btnOpt.subControls = QStyle::SC_ToolButton;
396-
btnOpt.rect = optionsButtonVisualRect;
477+
//NMC customization
478+
btnOpt.rect = currentButtonRectPos;
479+
//make sure the button is not too far away from the left border
480+
btnOpt.rect.setRight(btnOpt.rect.x() + btnOpt.rect.width() + 4);
481+
482+
// Create QPainterPath with rounded corners
483+
QPainterPath path;
484+
path.addRoundedRect(btnOpt.rect, 4, 4); // 4 ist der Radius für die abgerundeten Ecken
485+
486+
// Draw border line
487+
QPen borderPen(QColor(0, 0, 0)); // Beispiel: Schwarzer Rand
488+
borderPen.setWidth(1);
489+
painter->setPen(borderPen);
490+
painter->drawPath(path);
491+
492+
// Fill the rectangle
493+
painter->fillPath(path, Qt::transparent);
494+
495+
// Draw the icon in rectangle
397496
btnOpt.icon = _iconMore;
398497
const auto buttonSize = QApplication::style()->pixelMetric(QStyle::PM_ButtonIconSize);
399498
btnOpt.iconSize = QSize(buttonSize, buttonSize);
400-
QApplication::style()->drawComplexControl(QStyle::CC_ToolButton, &btnOpt, painter);
499+
500+
// Set icon position
501+
int iconX = btnOpt.rect.x() + btnOpt.rect.width()/5;
502+
int iconY = btnOpt.rect.y() + (btnOpt.rect.height() - btnOpt.iconSize.height()) / 2;
503+
504+
painter->drawPixmap(iconX, iconY, btnOpt.icon.pixmap(btnOpt.iconSize));
505+
506+
//Add text
507+
const QString buttonText = QCoreApplication::translate("", "MORE");
508+
painter->setFont(btnOpt.font);
509+
painter->setPen(option.palette.color(QPalette::ButtonText));
510+
int textX = iconX + btnOpt.iconSize.width() + 10;
511+
int textY = iconY;
512+
int textWidth = currentButtonRectPos.x() + currentButtonRectPos.width() - textX;
513+
int textHeight = btnOpt.fontMetrics.height();
514+
515+
painter->drawText(QRect(textX, textY, textWidth, textHeight), Qt::AlignLeft | Qt::AlignVCenter, buttonText);
401516
}
517+
518+
painter->restore();
402519
}
403520

404521
bool FolderStatusDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,

src/gui/folderstatusdelegate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class FolderStatusDelegate : public QStyledItemDelegate
5454
static QRect errorsListRect(QRect within);
5555
static QRect sandboxButtonRect(QRect errorBannerRect);
5656
static int rootFolderHeightWithoutErrors(const QFontMetrics &fm, const QFontMetrics &aliasFm);
57+
static QRect moreRectPos(const QRect &rectIndex);
5758

5859
public slots:
5960
void slotStyleChanged();
@@ -65,6 +66,7 @@ public slots:
6566
QPersistentModelIndex _pressedIndex;
6667

6768
QIcon _iconMore;
69+
QStyleOptionViewItem _newOption;
6870
};
6971

7072
} // namespace OCC

0 commit comments

Comments
 (0)