kfnkeys.cpp 3.53 KB
Newer Older
1 2 3
/*****************************************************************************
 * Copyright (C) 2000 Shie Erlich <krusader@users.sourceforge.net>           *
 * Copyright (C) 2000 Rafi Yanai <krusader@users.sourceforge.net>            *
Davide Gianforte's avatar
Davide Gianforte committed
4
 * Copyright (C) 2004-2020 Krusader Krew [https://krusader.org]              *
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *                                                                           *
 * 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/].         *
 *****************************************************************************/
Rafi Yanai's avatar
Rafi Yanai committed
21

Fathi Boudra's avatar
Fathi Boudra committed
22 23
#include "kfnkeys.h"

24 25
// QtWidgets
#include <QGridLayout>
Fathi Boudra's avatar
Fathi Boudra committed
26

Simon Persson's avatar
Simon Persson committed
27 28
#include <KI18n/KLocalizedString>

Rafi Yanai's avatar
Rafi Yanai committed
29
#include "../defaults.h"
30
#include "../krmainwindow.h"
Jan Lepper's avatar
Jan Lepper committed
31
#include "../kractions.h"
32
#include "../Panel/listpanelactions.h"
Rafi Yanai's avatar
Rafi Yanai committed
33

34
KFnKeys::KFnKeys(QWidget *parent, KrMainWindow *mainWindow) :
35
        QWidget(parent), mainWindow(mainWindow)
Fathi Boudra's avatar
Fathi Boudra committed
36
{
37 38 39 40 41 42 43 44 45 46 47
    buttonList << setup(mainWindow->listPanelActions()->actRenameF2, i18n("Rename"))
               << setup(mainWindow->listPanelActions()->actViewFileF3, i18n("View"))
               << setup(mainWindow->listPanelActions()->actEditFileF4, i18n("Edit"))
               << setup(mainWindow->listPanelActions()->actCopyF5, i18n("Copy"))
               << setup(mainWindow->listPanelActions()->actMoveF6, i18n("Move"))
               << setup(mainWindow->listPanelActions()->actNewFolderF7, i18n("Mkdir"))
               << setup(mainWindow->listPanelActions()->actDeleteF8, i18n("Delete"))
               << setup(mainWindow->listPanelActions()->actTerminalF9, i18n("Term"))
               << setup(mainWindow->krActions()->actF10Quit, i18n("Quit"));

    updateShortcuts();
Fathi Boudra's avatar
Fathi Boudra committed
48

49
    auto *layout = new QGridLayout(this);
Fathi Boudra's avatar
Fathi Boudra committed
50 51 52
    layout->setContentsMargins(0, 0, 0, 0);
    layout->setSpacing(0);

53
    int pos = 0;
Alexander Lohnau's avatar
Alexander Lohnau committed
54
    for(QPair<QPushButton *, QPair<QAction *, const QString&>> entry : qAsConst(buttonList)) {
55 56
        layout->addWidget(entry.first, 0, pos++);
    }
Fathi Boudra's avatar
Fathi Boudra committed
57
    layout->activate();
Rafi Yanai's avatar
Rafi Yanai committed
58 59
}

Fathi Boudra's avatar
Fathi Boudra committed
60 61
void KFnKeys::updateShortcuts()
{
62 63 64
    for(ButtonEntry entry : buttonList) {
        entry.first->setText(entry.second.first->shortcut().toString() + ' ' + entry.second.second);
    }
65 66
}

67 68
KFnKeys::ButtonEntry KFnKeys::setup(QAction *action, const QString &text)
{
69
    auto *button = new QPushButton(this);
70 71 72 73 74 75
    button->setMinimumWidth(45);
    button->setToolTip(action->toolTip());
    connect(button, &QPushButton::clicked, action, &QAction::trigger);
    return QPair<QPushButton *, QPair<QAction *, QString>>(button,
                                                           QPair<QAction *, QString>(action, text));
}