File indexing completed on 2024-04-28 17:06:04

0001 /*
0002     SPDX-FileCopyrightText: 2006 Václav Juza <vaclavjuza@gmail.com>
0003     SPDX-FileCopyrightText: 2006-2022 Krusader Krew <https://krusader.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "kcmdmodebutton.h"
0009 
0010 #include "../icon.h"
0011 #include "../kractions.h"
0012 
0013 // QtWidgets
0014 #include <QMenu>
0015 
0016 #include <KI18n/KLocalizedString>
0017 #include <KWidgetsAddons/KActionMenu>
0018 
0019 /**
0020  * KCMDModeButton class, which represents a button with popup menu to switch
0021  * the mode of the krusader built-in command-line
0022  */
0023 KCMDModeButton::KCMDModeButton(QWidget *parent)
0024     : QToolButton(parent)
0025 {
0026     /* // from the old terminal-button:
0027       setText( i18n( "If pressed, Krusader executes command line in a terminal." ) );
0028       setToolTip( i18n( "If pressed, Krusader executes command line in a terminal." ) );
0029       QWhatsThis::add( terminal, i18n(
0030                             "The 'run in terminal' button allows Krusader "
0031                             "to run console (or otherwise non-graphical) "
0032                             "programs in a terminal of your choice. If it's "
0033                             "pressed, terminal mode is active." ) );
0034     */
0035     setIcon(Icon("utilities-terminal"));
0036     adjustSize();
0037     action = new KActionMenu(i18n("Execution mode"), this);
0038     Q_CHECK_PTR(action);
0039     for (int i = 0; KrActions::execTypeArray[i] != nullptr; i++) {
0040         action->addAction(*KrActions::execTypeArray[i]);
0041     }
0042     QMenu *pP = action->menu();
0043     Q_CHECK_PTR(pP);
0044     setMenu(pP);
0045     setPopupMode(QToolButton::InstantPopup);
0046     setAcceptDrops(false);
0047 }
0048 
0049 KCMDModeButton::~KCMDModeButton()
0050 {
0051     delete action;
0052 }
0053 
0054 /** called when clicked to the button */
0055 void KCMDModeButton::showMenu()
0056 {
0057     QMenu *pP = menu();
0058     if (pP) {
0059         menu()->exec(mapToGlobal(QPoint(0, 0)));
0060     }
0061 }