File indexing completed on 2024-04-28 17:06:03
0001 /* 0002 SPDX-FileCopyrightText: 2004 Shie Erlich <erlich@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2004 Rafi Yanai <yanai@users.sourceforge.net> 0004 SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "dirhistorybutton.h" 0010 #include "../Panel/dirhistoryqueue.h" 0011 #include "../icon.h" 0012 0013 #include "../FileSystem/filesystem.h" 0014 0015 // QtCore 0016 #include <QDebug> 0017 #include <QDir> 0018 // QtGui 0019 #include <QPixmap> 0020 // QtWidgets 0021 #include <QMenu> 0022 0023 #include <KI18n/KLocalizedString> 0024 0025 DirHistoryButton::DirHistoryButton(DirHistoryQueue *hQ, QWidget *parent) 0026 : QToolButton(parent) 0027 { 0028 setAutoRaise(true); 0029 setIcon(Icon("chronometer")); 0030 setText(i18n("Open the folder history list")); 0031 setToolTip(i18n("Open the folder history list")); 0032 setPopupMode(QToolButton::InstantPopup); 0033 setAcceptDrops(false); 0034 0035 popupMenu = new QMenu(this); 0036 Q_CHECK_PTR(popupMenu); 0037 0038 setMenu(popupMenu); 0039 0040 historyQueue = hQ; 0041 0042 connect(popupMenu, &QMenu::aboutToShow, this, &DirHistoryButton::slotAboutToShow); 0043 connect(popupMenu, &QMenu::triggered, this, &DirHistoryButton::slotPopupActivated); 0044 } 0045 0046 DirHistoryButton::~DirHistoryButton() = default; 0047 0048 void DirHistoryButton::showMenu() 0049 { 0050 QMenu *pP = menu(); 0051 if (pP) { 0052 menu()->exec(mapToGlobal(QPoint(0, height()))); 0053 } 0054 } 0055 /** No descriptions */ 0056 void DirHistoryButton::slotPopup() 0057 { 0058 // qDebug() << "History slot"; 0059 } 0060 /** No descriptions */ 0061 void DirHistoryButton::slotAboutToShow() 0062 { 0063 emit aboutToShow(); 0064 // qDebug() << "about to show"; 0065 popupMenu->clear(); 0066 0067 for (int i = 0; i < historyQueue->count(); i++) { 0068 QAction *act = popupMenu->addAction(historyQueue->get(i).toDisplayString()); 0069 act->setData(QVariant(i)); 0070 if (historyQueue->currentPos() == i) { 0071 act->setCheckable(true); 0072 act->setChecked(true); 0073 } 0074 } 0075 } 0076 /** No descriptions */ 0077 void DirHistoryButton::slotPopupActivated(QAction *action) 0078 { 0079 if (action && action->data().canConvert<int>()) { 0080 int id = action->data().toInt(); 0081 emit gotoPos(id); 0082 } 0083 }