QTfrontend/ui/widget/keybinder.cpp
author alfadur
Wed, 28 Nov 2018 21:35:54 +0300
changeset 14340 97be4f6bf264
parent 14223 925e2c9877a8
child 14851 75b515a64202
permissions -rw-r--r--
add render module 🦔
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
     1
/*
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10108
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
     4
 *
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
     8
 *
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    12
 * GNU General Public License for more details.
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    13
 *
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    17
 */
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    18
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    19
#include "keybinder.h"
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    20
#include "HWApplication.h"
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    21
#include "DataManager.h"
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    22
#include <QHBoxLayout>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    23
#include <QScrollArea>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    24
#include <QTableWidget>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    25
#include <QTableWidgetItem>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    26
#include <QStandardItemModel>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    27
#include <QAbstractItemModel>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    28
#include <QListWidget>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    29
#include <QListWidgetItem>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    30
#include <QPushButton>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    31
#include <QHeaderView>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    32
#include <QComboBox>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    33
#include <QLabel>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    34
#include <QFrame>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    35
#include <QDebug>
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    36
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    37
KeyBinder::KeyBinder(QWidget * parent, const QString & helpText, const QString & defaultText, const QString & resetButtonText) : QWidget(parent)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    38
{
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    39
    this->defaultText = defaultText;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    40
    enableSignal = false;
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8346
diff changeset
    41
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    42
    // Two-column tab layout
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    43
    QHBoxLayout * pageKeysLayout = new QHBoxLayout(this);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    44
    pageKeysLayout->setSpacing(0);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    45
    pageKeysLayout->setContentsMargins(0, 0, 0, 0);
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8346
diff changeset
    46
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    47
    // Table for category list
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    48
    QVBoxLayout * catListContainer = new QVBoxLayout();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    49
    catListContainer->setContentsMargins(10, 10, 10, 10);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    50
    catList = new QListWidget();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    51
    catList->setFixedWidth(180);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    52
    catList->setStyleSheet("QListWidget::item { font-size: 14px; } QListWidget:hover { border-color: #F6CB1C; } QListWidget::item:selected { background: #150A61; color: yellow; }");
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    53
    catList->setFocusPolicy(Qt::NoFocus);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    54
    connect(catList, SIGNAL(currentRowChanged(int)), this, SLOT(changeBindingsPage(int)));
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    55
    catListContainer->addWidget(catList);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    56
    pageKeysLayout->addLayout(catListContainer);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    57
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    58
    // Reset all binds button
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    59
    if (!resetButtonText.isEmpty())
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    60
    {
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    61
        QPushButton * btnResetAll = new QPushButton(resetButtonText);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    62
        catListContainer->addWidget(btnResetAll);
12241
a0ed4caa6d35 Apply minimal padding to all text buttons in frontend
Wuzzy <almikes@aol.com>
parents: 11679
diff changeset
    63
        btnResetAll->setStyleSheet("padding: 5px 10px");
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    64
        btnResetAll->setFixedHeight(40);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    65
        catListContainer->setStretch(1, 0);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    66
        catListContainer->setSpacing(10);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    67
        connect(btnResetAll, SIGNAL(clicked()), this, SIGNAL(resetAllBinds()));
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    68
    }
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    69
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    70
    // Container for pages of key bindings
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    71
    QWidget * bindingsPagesContainer = new QWidget();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    72
    QVBoxLayout * rightLayout = new QVBoxLayout(bindingsPagesContainer);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    73
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    74
    // Scroll area for key bindings
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    75
    QScrollArea * scrollArea = new QScrollArea();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    76
    scrollArea->setContentsMargins(0, 0, 0, 0);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    77
    scrollArea->setWidget(bindingsPagesContainer);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    78
    scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    79
    scrollArea->setWidgetResizable(true);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    80
    scrollArea->setFrameShape(QFrame::NoFrame);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    81
    scrollArea->setStyleSheet("background: #130F2A;");
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    82
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    83
    // Add key binding pages to bindings tab
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    84
    pageKeysLayout->addWidget(scrollArea);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    85
    pageKeysLayout->setStretch(1, 1);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    86
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    87
    // Custom help text
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    88
    QLabel * helpLabel = new QLabel();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    89
    helpLabel->setText(helpText);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    90
    helpLabel->setStyleSheet("color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-radius: 10px; padding: auto 20px;");
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    91
    helpLabel->setFixedHeight(24);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    92
    rightLayout->addWidget(helpLabel, 0, Qt::AlignCenter);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    93
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    94
    // Category list and bind table row heights
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    95
    const int rowHeight = 20;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    96
    QSize catSize, headerSize;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    97
    catSize.setHeight(36);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    98
    headerSize.setHeight(24);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
    99
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   100
    // Category list header
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   101
    QListWidgetItem * catListHeader = new QListWidgetItem(tr("Category"));
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   102
    catListHeader->setSizeHint(headerSize);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   103
    catListHeader->setFlags(Qt::NoItemFlags);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   104
    catListHeader->setForeground(QBrush(QColor("#130F2A")));
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   105
    catListHeader->setBackground(QBrush(QColor("#F6CB1C")));
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   106
    catListHeader->setTextAlignment(Qt::AlignCenter);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   107
    catList->addItem(catListHeader);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   108
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   109
    // Populate
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   110
    bindingsPages = new QHBoxLayout();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   111
    bindingsPages->setContentsMargins(0, 0, 0, 0);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   112
    rightLayout->addLayout(bindingsPages);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   113
    QWidget * curPage = NULL;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   114
    QVBoxLayout * curLayout = NULL;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   115
    QTableWidget * curTable = NULL;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   116
    bool bFirstPage = true;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   117
    selectedBindTable = NULL;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   118
    bindComboBoxCellMappings = new QHash<QObject *, QTableWidgetItem *>();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   119
    bindCellComboBoxMappings = new QHash<QTableWidgetItem *, QComboBox *>();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   120
    for (int i = 0; i < BINDS_NUMBER; i++)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   121
    {
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   122
        if (cbinds[i].category != NULL)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   123
        {
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   124
            // Add stretch at end of previous layout
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   125
            if (curLayout != NULL) curLayout->insertStretch(-1, 1);
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8346
diff changeset
   126
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   127
            // Category list item
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   128
            QListWidgetItem * catItem = new QListWidgetItem(HWApplication::translate("binds (categories)", cbinds[i].category));
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   129
            catItem->setSizeHint(catSize);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   130
            catList->addItem(catItem);
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8346
diff changeset
   131
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   132
            // Create new page
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   133
            curPage = new QWidget();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   134
            curLayout = new QVBoxLayout(curPage);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   135
            curLayout->setSpacing(2);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   136
            bindingsPages->addWidget(curPage);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   137
            if (!bFirstPage) curPage->setVisible(false);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   138
        }
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   139
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   140
        // Description
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   141
        if (cbinds[i].description != NULL)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   142
        {
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   143
            QLabel * desc = new QLabel(HWApplication::translate("binds (descriptions)", cbinds[i].description));
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   144
            curLayout->addWidget(desc, 0);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   145
            QFrame * divider = new QFrame();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   146
            divider->setFrameShape(QFrame::HLine);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   147
            divider->setFrameShadow(QFrame::Plain);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   148
            curLayout->addWidget(divider, 0);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   149
        }
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   150
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   151
        // New table
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   152
        if (cbinds[i].category != NULL || cbinds[i].description != NULL)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   153
        {
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   154
            curTable = new QTableWidget(0, 2);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   155
            curTable->verticalHeader()->setVisible(false);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   156
            curTable->horizontalHeader()->setVisible(false);
12902
fc47fc4af6bd Finish porting. Seems to work, but no thorough testing has been performed
unc0rr
parents: 12703
diff changeset
   157
            curTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   158
            curTable->verticalHeader()->setDefaultSectionSize(rowHeight);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   159
            curTable->setShowGrid(false);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   160
            curTable->setStyleSheet("QTableWidget { border: none; } ");
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   161
            curTable->setSelectionBehavior(QAbstractItemView::SelectRows);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   162
            curTable->setSelectionMode(QAbstractItemView::SingleSelection);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   163
            curTable->setFocusPolicy(Qt::NoFocus);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   164
            connect(curTable, SIGNAL(itemSelectionChanged()), this, SLOT(bindSelectionChanged()));
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   165
            connect(curTable, SIGNAL(itemClicked(QTableWidgetItem *)), this, SLOT(bindCellClicked(QTableWidgetItem *)));
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   166
            curLayout->addWidget(curTable, 0);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   167
        }
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   168
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   169
        // Hidden combo box
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   170
        QComboBox * comboBox = CBBind[i] = new QComboBox(curTable);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   171
        comboBox->setModel((QAbstractItemModel*)DataManager::instance().bindsModel());
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   172
        comboBox->setVisible(false);
14223
925e2c9877a8 Increase width for key binding drop-down list
Wuzzy <Wuzzy2@mail.ru>
parents: 13314
diff changeset
   173
        comboBox->setMinimumWidth(400);
11679
d59b6f289e30 Increase size of many drop-down lists
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   174
        comboBox->setMaxVisibleItems(50);
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8346
diff changeset
   175
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   176
        // Table row
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   177
        int row = curTable->rowCount();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   178
        QTableWidgetItem * nameCell = new QTableWidgetItem(HWApplication::translate("binds", cbinds[i].name));
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   179
        nameCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   180
        curTable->insertRow(row);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   181
        curTable->setItem(row, 0, nameCell);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   182
        QTableWidgetItem * bindCell = new QTableWidgetItem(comboBox->currentText());
13314
2bdae461ae5f Show simple drop-down icon next to key binder widget
Wuzzy <Wuzzy2@mail.ru>
parents: 12902
diff changeset
   183
        QIcon dropDownIcon = QIcon();
2bdae461ae5f Show simple drop-down icon next to key binder widget
Wuzzy <Wuzzy2@mail.ru>
parents: 12902
diff changeset
   184
        QPixmap dd1 = QPixmap(":/res/dropdown.png");
2bdae461ae5f Show simple drop-down icon next to key binder widget
Wuzzy <Wuzzy2@mail.ru>
parents: 12902
diff changeset
   185
        QPixmap dd2 = QPixmap(":/res/dropdown_selected.png");
2bdae461ae5f Show simple drop-down icon next to key binder widget
Wuzzy <Wuzzy2@mail.ru>
parents: 12902
diff changeset
   186
        dropDownIcon.addPixmap(dd1, QIcon::Normal);
2bdae461ae5f Show simple drop-down icon next to key binder widget
Wuzzy <Wuzzy2@mail.ru>
parents: 12902
diff changeset
   187
        dropDownIcon.addPixmap(dd2, QIcon::Selected);
2bdae461ae5f Show simple drop-down icon next to key binder widget
Wuzzy <Wuzzy2@mail.ru>
parents: 12902
diff changeset
   188
        bindCell->setIcon(dropDownIcon);
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   189
        bindCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   190
        curTable->setItem(row, 1, bindCell);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   191
        curTable->resizeColumnsToContents();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   192
        curTable->setFixedHeight(curTable->verticalHeader()->length() + 10);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   193
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   194
        // Updates the text in the table cell
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   195
        connect(comboBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(bindChanged(const QString &)));
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   196
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   197
        // Map combo box and that row's cells to each other
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   198
        bindComboBoxCellMappings->insert(comboBox, bindCell);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   199
        bindCellComboBoxMappings->insert(nameCell, comboBox);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   200
        bindCellComboBoxMappings->insert(bindCell, comboBox);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   201
    }
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   202
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   203
    // Add stretch at end of last layout
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   204
    if (curLayout != NULL) curLayout->insertStretch(-1, 1);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   205
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   206
    // Go to first page
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   207
    catList->setCurrentItem(catList->item(1));
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   208
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   209
    enableSignal = true;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   210
}
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   211
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   212
KeyBinder::~KeyBinder()
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   213
{
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   214
    delete bindComboBoxCellMappings;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   215
    delete bindCellComboBoxMappings;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   216
}
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   217
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   218
// Switches between different pages of key binds
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   219
void KeyBinder::changeBindingsPage(int page)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   220
{
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   221
    page--; // Disregard first item (the list header)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   222
    int pages = bindingsPages->count();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   223
    for (int i = 0; i < pages; i++)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   224
        bindingsPages->itemAt(i)->widget()->setVisible(false);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   225
    bindingsPages->itemAt(page)->widget()->setVisible(true);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   226
}
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   227
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   228
// When a key bind combobox value is changed, updates the table cell text
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   229
void KeyBinder::bindChanged(const QString & text)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   230
{
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   231
    bindComboBoxCellMappings->value(sender())->setText(text);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   232
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   233
    if (enableSignal)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   234
    {
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   235
        for (int i = 0; i < BINDS_NUMBER; i++)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   236
        {
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   237
            if (CBBind[i] == sender())
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   238
            {
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   239
                emit bindUpdate(i);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   240
                break;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   241
            }
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   242
        }
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   243
    }
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   244
}
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   245
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   246
// When a row in a key bind table is clicked, this shows the popup
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   247
void KeyBinder::bindCellClicked(QTableWidgetItem * item)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   248
{
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   249
    QComboBox * box = bindCellComboBoxMappings->value(item);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   250
    QTableWidget * table = item->tableWidget();
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8346
diff changeset
   251
12703
f2690a0ccf19 QTfrontend: Fix flickering and bad offset of control config popup
Wuzzy <almikes@aol.com>
parents: 12241
diff changeset
   252
    box->move(
f2690a0ccf19 QTfrontend: Fix flickering and bad offset of control config popup
Wuzzy <almikes@aol.com>
parents: 12241
diff changeset
   253
        table->horizontalHeader()->sectionSize(0),
f2690a0ccf19 QTfrontend: Fix flickering and bad offset of control config popup
Wuzzy <almikes@aol.com>
parents: 12241
diff changeset
   254
        (table->verticalHeader()->defaultSectionSize() * (item->row() + 1)) - (box->height()) + 1
f2690a0ccf19 QTfrontend: Fix flickering and bad offset of control config popup
Wuzzy <almikes@aol.com>
parents: 12241
diff changeset
   255
    );
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   256
    box->showPopup();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   257
}
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   258
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   259
// When a new row in a bind table is *selected*, this clears selection in any other table
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   260
void KeyBinder::bindSelectionChanged()
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   261
{
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   262
    QTableWidget * theSender = (QTableWidget*)sender();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   263
    if (theSender != selectedBindTable)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   264
    {
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   265
        if (selectedBindTable != NULL)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   266
            selectedBindTable->clearSelection();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   267
        selectedBindTable = theSender;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   268
    }
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   269
}
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   270
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   271
// Set a combobox's index
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   272
void KeyBinder::setBindIndex(int keyIndex, int bindIndex)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   273
{
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   274
    enableSignal = false;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   275
    CBBind[keyIndex]->setCurrentIndex(bindIndex);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   276
    enableSignal = true;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   277
}
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   278
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   279
// Return a combobox's selected index
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   280
int KeyBinder::bindIndex(int keyIndex)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   281
{
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   282
    return CBBind[keyIndex]->currentIndex();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   283
}
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   284
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   285
// Clears selection and goes to first category
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   286
void KeyBinder::resetInterface()
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   287
{
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   288
    enableSignal = false;
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8346
diff changeset
   289
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   290
    catList->setCurrentItem(catList->item(1));
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   291
    changeBindingsPage(1);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   292
    if (selectedBindTable != NULL)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   293
    {
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   294
        selectedBindTable->clearSelection();
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   295
        selectedBindTable = NULL;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   296
    }
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8346
diff changeset
   297
8346
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   298
    // Default bind text
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   299
    DataManager::instance().bindsModel()->item(0)->setData(defaultText, Qt::DisplayRole);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   300
    for (int i = 0; i < BINDS_NUMBER; i++)
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   301
    {
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   302
        CBBind[i]->setModel(DataManager::instance().bindsModel());
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   303
        CBBind[i]->setCurrentIndex(0);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   304
        bindComboBoxCellMappings->value(CBBind[i])->setText(defaultText);
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   305
    }
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   306
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   307
    enableSignal = true;
3443e0de2c9d GCI2012: Advanced Keyboard Configuration
dag10
parents:
diff changeset
   308
}