1 /*****************************************************************************
2 * Copyright (C) 2004 Shie Erlich <erlich@users.sourceforge.net> *
3 * Copyright (C) 2004 Rafi Yanai <yanai@users.sourceforge.net> *
4 * Copyright (C) 2004-2019 Krusader Krew [https://krusader.org] *
5 * *
6 * This file is part of Krusader [https://krusader.org]. *
7 * *
8 * Krusader is free software: you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation, either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * Krusader is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with Krusader. If not, see [http://www.gnu.org/licenses/]. *
20 *****************************************************************************/
21
22 #include "dirhistorybutton.h"
23 #include "../icon.h"
24 #include "../Panel/dirhistoryqueue.h"
25
26 #include "../FileSystem/filesystem.h"
27
28 // QtCore
29 #include <QDebug>
30 #include <QDir>
31 // QtGui
32 #include <QPixmap>
33 // QtWidgets
34 #include <QMenu>
35
36 #include <KI18n/KLocalizedString>
37
DirHistoryButton(DirHistoryQueue * hQ,QWidget * parent)38 DirHistoryButton::DirHistoryButton(DirHistoryQueue* hQ, QWidget *parent) : QToolButton(parent)
39 {
40 setAutoRaise(true);
41 setIcon(Icon("chronometer"));
42 setText(i18n("Open the folder history list"));
43 setToolTip(i18n("Open the folder history list"));
44 setPopupMode(QToolButton::InstantPopup);
45 setAcceptDrops(false);
46
47 popupMenu = new QMenu(this);
48 Q_CHECK_PTR(popupMenu);
49
50 setMenu(popupMenu);
51
52 historyQueue = hQ;
53
54 connect(popupMenu, SIGNAL(aboutToShow()), this, SLOT(slotAboutToShow()));
55 connect(popupMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotPopupActivated(QAction*)));
56 }
57
~DirHistoryButton()58 DirHistoryButton::~DirHistoryButton() {}
59
showMenu()60 void DirHistoryButton::showMenu()
61 {
62 QMenu * pP = menu();
63 if (pP) {
64 menu() ->exec(mapToGlobal(QPoint(0, height())));
65 }
66 }
67 /** No descriptions */
slotPopup()68 void DirHistoryButton::slotPopup()
69 {
70 // qDebug() << "History slot";
71 }
72 /** No descriptions */
slotAboutToShow()73 void DirHistoryButton::slotAboutToShow()
74 {
75 emit aboutToShow();
76 // qDebug() << "about to show";
77 popupMenu->clear();
78
79 for (int i = 0; i < historyQueue->count(); i++) {
80 QAction *act = popupMenu->addAction(historyQueue->get(i).toDisplayString());
81 act->setData(QVariant(i));
82 if(historyQueue->currentPos() == i) {
83 act->setCheckable(true);
84 act->setChecked(true);
85 }
86 }
87 }
88 /** No descriptions */
slotPopupActivated(QAction * action)89 void DirHistoryButton::slotPopupActivated(QAction * action)
90 {
91 if (action && action->data().canConvert<int>()) {
92 int id = action->data().toInt();
93 emit gotoPos(id);
94 }
95 }
96
97