1 /*****************************************************************************
2 * Copyright (C) 2006 Václav Juza <vaclavjuza@gmail.com> *
3 * Copyright (C) 2006-2019 Krusader Krew [https://krusader.org] *
4 * *
5 * This file is part of Krusader [https://krusader.org]. *
6 * *
7 * Krusader is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * Krusader is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with Krusader. If not, see [http://www.gnu.org/licenses/]. *
19 *****************************************************************************/
20
21 #include "kcmdmodebutton.h"
22
23 #include "../kractions.h"
24 #include "../icon.h"
25
26 // QtWidgets
27 #include <QMenu>
28
29 #include <KI18n/KLocalizedString>
30 #include <KWidgetsAddons/KActionMenu>
31
32 /**
33 * KCMDModeButton class, which represents a button with popup menu to switch
34 * the mode of the krusader built-in command-line
35 */
KCMDModeButton(QWidget * parent)36 KCMDModeButton::KCMDModeButton(QWidget *parent) : QToolButton(parent)
37 {
38 /* // from the old terminal-button:
39 setText( i18n( "If pressed, Krusader executes command line in a terminal." ) );
40 setToolTip( i18n( "If pressed, Krusader executes command line in a terminal." ) );
41 QWhatsThis::add( terminal, i18n(
42 "The 'run in terminal' button allows Krusader "
43 "to run console (or otherwise non-graphical) "
44 "programs in a terminal of your choice. If it's "
45 "pressed, terminal mode is active." ) );
46 */
47 setIcon(Icon("utilities-terminal"));
48 adjustSize();
49 action = new KActionMenu(i18n("Execution mode"), this);
50 Q_CHECK_PTR(action);
51 for (int i = 0; KrActions::execTypeArray[i] != 0; i++) {
52 action->addAction(*KrActions::execTypeArray[i]);
53 }
54 QMenu *pP = action->menu();
55 Q_CHECK_PTR(pP);
56 setMenu(pP);
57 setPopupMode(QToolButton::InstantPopup);
58 setAcceptDrops(false);
59 }
60
~KCMDModeButton()61 KCMDModeButton::~KCMDModeButton()
62 {
63 delete action;
64 }
65
66 /** called when clicked to the button */
showMenu()67 void KCMDModeButton::showMenu()
68 {
69 QMenu * pP = menu();
70 if (pP) {
71 menu() ->exec(mapToGlobal(QPoint(0, 0)));
72 }
73 }
74
75