diff --git a/krusader/Panel/sidebar.cpp b/krusader/Panel/sidebar.cpp index dae02d56..8ca17e57 100644 --- a/krusader/Panel/sidebar.cpp +++ b/krusader/Panel/sidebar.cpp @@ -1,289 +1,290 @@ /***************************************************************************** * Copyright (C) 2003 Shie Erlich * * Copyright (C) 2003 Rafi Yanai * * Copyright (C) 2004-2020 Krusader Krew [https://krusader.org] * * * * This file is part of Krusader [https://krusader.org]. * * * * Krusader is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 2 of the License, or * * (at your option) any later version. * * * * Krusader is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with Krusader. If not, see [http://www.gnu.org/licenses/]. * *****************************************************************************/ #include "sidebar.h" #include "krfiletreeview.h" #include "krpanel.h" #include "panelfunc.h" #include "viewactions.h" #include "../defaults.h" #include "../icon.h" +#include "../compat.h" #include "../Dialogs/krsqueezedtextlabel.h" #include "../FileSystem/fileitem.h" #include "../FileSystem/filesystem.h" #include "../KViewer/diskusageviewer.h" #include "../KViewer/panelviewer.h" #include "PanelView/krview.h" #include "PanelView/krviewitem.h" // QtCore #include #include // QtWidgets #include #include #include #include Sidebar::Sidebar(QWidget *parent) : QWidget(parent), stack(nullptr), imageFilePreview(nullptr), pjob(nullptr) { auto * layout = new QGridLayout(this); layout->setContentsMargins(0, 0, 0, 0); // create the label+buttons setup dataLine = new KrSqueezedTextLabel(this); KConfigGroup lg(krConfig, "Look&Feel"); dataLine->setFont(lg.readEntry("Filelist Font", _FilelistFont)); // --- hack: setup colors to be the same as an inactive panel dataLine->setBackgroundRole(QPalette::Window); int sheight = QFontMetrics(dataLine->font()).height() + 4; dataLine->setMaximumHeight(sheight); btns = new QButtonGroup(this); btns->setExclusive(true); - connect(btns, QOverload::of(&QButtonGroup::buttonClicked), this, &Sidebar::tabSelected); + connect(btns, QOverload::of(&QButtonGroup::QBUTTONGROUP_BUTTONCLICKED), this, &Sidebar::tabSelected); treeBtn = new QToolButton(this); treeBtn->setToolTip(i18n("Tree Panel: a tree view of the local file system")); treeBtn->setIcon(Icon("view-list-tree")); treeBtn->setFixedSize(20, 20); treeBtn->setCheckable(true); btns->addButton(treeBtn, Tree); previewBtn = new QToolButton(this); previewBtn->setToolTip(i18n("Preview Panel: display a preview of the current file")); previewBtn->setIcon(Icon("view-preview")); previewBtn->setFixedSize(20, 20); previewBtn->setCheckable(true); btns->addButton(previewBtn, Preview); viewerBtn = new QToolButton(this); viewerBtn->setToolTip(i18n("View Panel: view the current file")); viewerBtn->setIcon(Icon("zoom-original")); viewerBtn->setFixedSize(20, 20); viewerBtn->setCheckable(true); btns->addButton(viewerBtn, View); duBtn = new QToolButton(this); duBtn->setToolTip(i18n("Disk Usage Panel: view the usage of a folder")); duBtn->setIcon(Icon("kr_diskusage")); duBtn->setFixedSize(20, 20); duBtn->setCheckable(true); btns->addButton(duBtn, DskUsage); layout->addWidget(dataLine, 0, 0); layout->addWidget(treeBtn, 0, 1); layout->addWidget(previewBtn, 0, 2); layout->addWidget(viewerBtn, 0, 3); layout->addWidget(duBtn, 0, 4); // create a widget stack on which to put the parts stack = new QStackedWidget(this); // create the tree part ---------- tree = new KrFileTreeView(stack); tree->setProperty("KrusaderWidgetId", QVariant(Tree)); stack->addWidget(tree); // NOTE: the F2 key press event is caught before it gets to the tree tree->setEditTriggers(QAbstractItemView::EditKeyPressed); // connecting signal to signal connect(tree, &KrFileTreeView::urlActivated, this, &Sidebar::urlActivated); // create the quickview part ------ imageFilePreview = new KImageFilePreview(stack); imageFilePreview->setProperty("KrusaderWidgetId", QVariant(Preview)); stack->addWidget(imageFilePreview); // create the panelview fileViewer = new PanelViewer(stack); fileViewer->setProperty("KrusaderWidgetId", QVariant(View)); // kparts demand too much width QSizePolicy sizePolicy = fileViewer->sizePolicy(); sizePolicy.setHorizontalPolicy(QSizePolicy::Ignored); fileViewer->setSizePolicy(sizePolicy); stack->addWidget(fileViewer); connect(fileViewer, &PanelViewer::openUrlRequest, this, &Sidebar::handleOpenUrlRequest); // create the disk usage view diskusage = new DiskUsageViewer(stack); diskusage->setStatusLabel(dataLine, i18n("Disk Usage:")); diskusage->setProperty("KrusaderWidgetId", QVariant(DskUsage)); stack->addWidget(diskusage); connect(diskusage, &DiskUsageViewer::openUrlRequest, this, &Sidebar::handleOpenUrlRequest); // -------- finish the layout (General one) layout->addWidget(stack, 1, 0, 1, 5); hide(); // for not to open the 3rd hand tool at start (selecting the last used tab) setCurrentPage(0); } Sidebar::~Sidebar() = default; void Sidebar::saveSettings(const KConfigGroup& cfg) const { tree->saveSettings(cfg); } void Sidebar::restoreSettings(const KConfigGroup &cfg) { tree->restoreSettings(cfg); } void Sidebar::setCurrentPage(int id) { QAbstractButton * curr = btns->button(id); if (curr) { curr->click(); } } void Sidebar::show() { QWidget::show(); tabSelected(currentPage()); } void Sidebar::hide() { QWidget::hide(); if (currentPage() == View) fileViewer->closeUrl(); if (currentPage() == DskUsage) diskusage->closeUrl(); } void Sidebar::focusInEvent(QFocusEvent*) { switch (currentPage()) { case Preview: if (!isHidden()) imageFilePreview->setFocus(); break; case View: if (!isHidden() && fileViewer->part() && fileViewer->part()->widget()) fileViewer->part()->widget()->setFocus(); break; case DskUsage: if (!isHidden() && diskusage->getWidget() && diskusage->getWidget()->currentWidget()) diskusage->getWidget()->currentWidget()->setFocus(); break; case Tree: if (!isHidden()) tree->setFocus(); break; } } void Sidebar::handleOpenUrlRequest(const QUrl &url) { QMimeDatabase db; QMimeType mime = db.mimeTypeForUrl(url); if (mime.isValid() && mime.name() == "inode/directory") ACTIVE_PANEL->func->openUrl(url); } void Sidebar::tabSelected(int id) { QUrl url; const FileItem *fileitem = nullptr; if (ACTIVE_PANEL && ACTIVE_PANEL->view) fileitem = ACTIVE_PANEL->func->files()->getFileItem(ACTIVE_PANEL->view->getCurrentItem()); if(fileitem) url = fileitem->getUrl(); // if tab is tree, set something logical in the data line switch (id) { case Tree: stack->setCurrentWidget(tree); dataLine->setText(i18n("Tree:")); if (!isHidden()) tree->setFocus(); if (ACTIVE_PANEL) tree->setCurrentUrl(ACTIVE_PANEL->virtualPath()); break; case Preview: stack->setCurrentWidget(imageFilePreview); dataLine->setText(i18n("Preview:")); update(fileitem); break; case View: stack->setCurrentWidget(fileViewer); dataLine->setText(i18n("View:")); update(fileitem); if (!isHidden() && fileViewer->part() && fileViewer->part()->widget()) fileViewer->part()->widget()->setFocus(); break; case DskUsage: stack->setCurrentWidget(diskusage); dataLine->setText(i18n("Disk Usage:")); update(fileitem); if (!isHidden() && diskusage->getWidget() && diskusage->getWidget()->currentWidget()) diskusage->getWidget()->currentWidget()->setFocus(); break; } if (id != View) fileViewer->closeUrl(); } // decide which part to update, if at all void Sidebar::update(const FileItem *fileitem) { if (isHidden()) return; QUrl url; if(fileitem) url = fileitem->getUrl(); switch (currentPage()) { case Preview: imageFilePreview->showPreview(url); dataLine->setText(i18n("Preview: %1", url.fileName())); break; case View: if(fileitem && !fileitem->isDir() && fileitem->isReadable()) fileViewer->openUrl(fileitem->getUrl()); else fileViewer->closeUrl(); dataLine->setText(i18n("View: %1", url.fileName())); break; case DskUsage: { if(fileitem && !fileitem->isDir()) url = KIO::upUrl(url); dataLine->setText(i18n("Disk Usage: %1", url.fileName())); diskusage->openUrl(url); } break; case Tree: // nothing to do break; } } void Sidebar::onPanelPathChange(const QUrl &url) { switch (currentPage()) { case Tree: if (url.isLocalFile()) { tree->setCurrentUrl(url); // synchronize panel path with tree path } break; } } diff --git a/krusader/compat.h b/krusader/compat.h index af2d79cc..02aa741a 100644 --- a/krusader/compat.h +++ b/krusader/compat.h @@ -1,121 +1,135 @@ /***************************************************************************** * Copyright (C) 2019-2020 Krusader Krew [https://krusader.org] * * * * This file is part of Krusader [https://krusader.org]. * * * * Krusader is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 2 of the License, or * * (at your option) any later version. * * * * Krusader is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with Krusader. If not, see [http://www.gnu.org/licenses/]. * *****************************************************************************/ #ifndef _COMPAT_H_ #define _COMPAT_H_ #include #if KIO_VERSION >= QT_VERSION_CHECK(5, 48, 0) #define UDS_ENTRY_INSERT(A, B) UDSEntry::fastInsert((A), (B)); #else #define UDS_ENTRY_INSERT(A, B) UDSEntry::insert((A), (B)); #endif +/** + * QButtonGroup::buttonClicked(int id) was made obsoleted in QT 5.15 in + * favor of QButtonGroup::idClicked(int id) + * + * https://doc.qt.io/qt-5.15/qbuttongroup-obsolete.html#buttonClicked-1 + * + * This can be removed when the qt minimum version required will be >= 5.15 + */ +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + #define QBUTTONGROUP_BUTTONCLICKED idClicked +#else + #define QBUTTONGROUP_BUTTONCLICKED buttonClicked +#endif + /** * QResource::isCompressed() was made obsoleted in QT 5.15 in * favor of QResource::Compression QResource::compressionAlgorithm() * * https://doc.qt.io/qt-5.15/qresource-obsolete.html#isCompressed * * This can be removed when the qt minimum version required will be >= 5.13 */ #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) #define QRESOURCE_ISCOMPRESSED(A) (A).compressionAlgorithm() != QResource::NoCompression #else #define QRESOURCE_ISCOMPRESSED(A) (A).isCompressed() #endif /** * QString::split(QChar sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs = Qt::CaseSensitive) * was made obsoleted in QT 5.15 in favor of the namespaced Qt::endl * * https://doc.qt.io/qt-5.15/qstring-obsolete.html#split-2 * * This can be removed when the qt minimum version required will be >= 5.15 */ #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) #define SKIP_EMPTY_PARTS Qt::SkipEmptyParts #else #define SKIP_EMPTY_PARTS QString::SkipEmptyParts #endif /** * QTextSteam::endl() was made obsoleted in QT 5.15 in * favor of the namespaced Qt::endl * * https://doc.qt.io/qt-5.15/qtextstream-obsolete.html#endl * * This can be removed when the qt minimum version required will be >= 5.15 */ #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) #define QT_ENDL Qt::endl #else #define QT_ENDL endl #endif /** * QComboBox::activated(const QString &text) was made obsoleted in QT 5.15 in * favor of QComboBox::textActivated(const QString &text) * * https://doc.qt.io/qt-5.15/qcombobox-obsolete.html#activated-1 * * This can be removed when the qt minimum version required will be >= 5.14 */ #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) #define QCOMBOBOX_ACTIVATED textActivated #else #define QCOMBOBOX_ACTIVATED activated #endif /** * QComboBox::highlighted(const QString &text) was made obsoleted in QT 5.15 in * favor of QComboBox::textHighlighted(const QString &text) * * https://doc.qt.io/qt-5.15/qcombobox-obsolete.html#highlighted-1 * * This can be removed when the qt minimum version required will be >= 5.14 */ #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) #define QCOMBOBOX_HIGHLIGHTED textHighlighted #else #define QCOMBOBOX_HIGHLIGHTED highlighted #endif /** * QFontMetrics::width(const QString&, int) was made obsoleted in QT 5.11 in * favor of QFontMetrics::horizontalAdvance(const QString &, int) * * https://doc.qt.io/archives/qt-5.11/qfontmetrics-obsolete.html#width * * This can be removed when the qt minimum version required will be >= 5.11 */ #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) #define QFONTMETRICS_WIDTH(A) horizontalAdvance(A) #else #define QFONTMETRICS_WIDTH(A) width(A) #endif #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) #define SET_TAB_STOP_DISTANCE(X) setTabStopDistance(X) #else #define SET_TAB_STOP_DISTANCE(X) setTabStopWidth(X) #endif #endif