ShortcutsDialog.cpp   ShortcutsDialog.cpp 
skipping to change at line 22 skipping to change at line 22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include <QDialog> #include <QDialog>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QDebug>
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelShortcutMgr.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelShortcutGroup.hpp" #include "StelActionMgr.hpp"
#include "ShortcutLineEdit.hpp" #include "ShortcutLineEdit.hpp"
#include "ShortcutsDialog.hpp" #include "ShortcutsDialog.hpp"
#include "ui_shortcutsDialog.h" #include "ui_shortcutsDialog.h"
ShortcutsFilterModel::ShortcutsFilterModel(QObject* parent) : ShortcutsFilterModel::ShortcutsFilterModel(QObject* parent) :
QSortFilterProxyModel(parent) QSortFilterProxyModel(parent)
{ {
// //
} }
skipping to change at line 61 skipping to change at line 60
QModelIndex index = sourceModel()->index(source_row, filterK eyColumn()); QModelIndex index = sourceModel()->index(source_row, filterK eyColumn());
for (int row = 0; row < sourceModel()->rowCount(index); row+ +) for (int row = 0; row < sourceModel()->rowCount(index); row+ +)
{ {
if (filterAcceptsRow(row, index)) if (filterAcceptsRow(row, index))
return true; return true;
} }
} }
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_pa rent); return QSortFilterProxyModel::filterAcceptsRow(source_row, source_pa rent);
} }
ShortcutsDialog::ShortcutsDialog() : ShortcutsDialog::ShortcutsDialog(QObject* parent) :
StelDialog(parent),
ui(new Ui_shortcutsDialogForm), ui(new Ui_shortcutsDialogForm),
filterModel(new ShortcutsFilterModel(this)), filterModel(new ShortcutsFilterModel(this)),
mainModel(new QStandardItemModel(this)) mainModel(new QStandardItemModel(this))
{ {
shortcutMgr = StelApp::getInstance().getStelShortcutManager(); actionMgr = StelApp::getInstance().getStelActionManager();
} }
ShortcutsDialog::~ShortcutsDialog() ShortcutsDialog::~ShortcutsDialog()
{ {
collisionItems.clear(); collisionItems.clear();
delete ui; delete ui;
ui = NULL; ui = NULL;
} }
void ShortcutsDialog::drawCollisions() void ShortcutsDialog::drawCollisions()
skipping to change at line 148 skipping to change at line 148
polish(); polish();
} }
bool ShortcutsDialog::prefixMatchKeySequence(const QKeySequence& ks1, bool ShortcutsDialog::prefixMatchKeySequence(const QKeySequence& ks1,
const QKeySequence& ks2) const QKeySequence& ks2)
{ {
if (ks1.isEmpty() || ks2.isEmpty()) if (ks1.isEmpty() || ks2.isEmpty())
{ {
return false; return false;
} }
for (uint i = 0; i < qMin(ks1.count(), ks2.count()); ++i) for (int i = 0; i < qMin(ks1.count(), ks2.count()); ++i)
{ {
if (ks1[i] != ks2[i]) if (ks1[i] != ks2[i])
{ {
return false; return false;
} }
} }
return true; return true;
} }
QList<QStandardItem*> ShortcutsDialog::findCollidingItems(QKeySequence ks) QList<QStandardItem*> ShortcutsDialog::findCollidingItems(QKeySequence ks)
skipping to change at line 245 skipping to change at line 245
ui->applyButton->setEnabled(false); ui->applyButton->setEnabled(false);
} }
else else
{ {
ui->applyButton->setEnabled(true); ui->applyButton->setEnabled(true);
} }
handleCollisions(editor); handleCollisions(editor);
polish(); polish();
} }
void ShortcutsDialog::applyChanges() const void ShortcutsDialog::applyChanges()
{ {
// get ids stored in tree // get ids stored in tree
QModelIndex index = QModelIndex index =
filterModel->mapToSource(ui->shortcutsTreeView->currentIndex ()); filterModel->mapToSource(ui->shortcutsTreeView->currentIndex ());
if (!index.isValid()) if (!index.isValid())
return; return;
index = index.sibling(index.row(), 0); index = index.sibling(index.row(), 0);
QStandardItem* currentItem = mainModel->itemFromIndex(index); QStandardItem* currentItem = mainModel->itemFromIndex(index);
QString actionId = currentItem->data(Qt::UserRole).toString(); QString actionId = currentItem->data(Qt::UserRole).toString();
QString groupId = currentItem->parent()->data(Qt::UserRole).toString
(); StelAction* action = actionMgr->findAction(actionId);
// changing keys in shortcuts action->setShortcut(ui->primaryShortcutEdit->getKeySequence().toStri
shortcutMgr->changeActionPrimaryKey(actionId, groupId, ui->primarySh ng());
ortcutEdit->getKeySequence()); action->setAltShortcut(ui->altShortcutEdit->getKeySequence().toStrin
shortcutMgr->changeActionAltKey(actionId, groupId, ui->altShortcutEd g());
it->getKeySequence()); updateShortcutsItem(action);
// no need to change displaying information, as it changed in mgr, a
nd will be updated in connected slot
// save shortcuts to file // save shortcuts to file
shortcutMgr->saveShortcuts(); actionMgr->saveShortcuts();
// nothing to apply until edits' content changes // nothing to apply until edits' content changes
ui->applyButton->setEnabled(false); ui->applyButton->setEnabled(false);
} }
void ShortcutsDialog::switchToEditors(const QModelIndex& index) void ShortcutsDialog::switchToEditors(const QModelIndex& index)
{ {
QModelIndex mainIndex = filterModel->mapToSource(index); QModelIndex mainIndex = filterModel->mapToSource(index);
QStandardItem* item = mainModel->itemFromIndex(mainIndex); QStandardItem* item = mainModel->itemFromIndex(mainIndex);
if (itemIsEditable(item)) if (itemIsEditable(item))
skipping to change at line 289 skipping to change at line 289
{ {
ui->setupUi(dialog); ui->setupUi(dialog);
resetModel(); resetModel();
filterModel->setSourceModel(mainModel); filterModel->setSourceModel(mainModel);
filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
filterModel->setSortCaseSensitivity(Qt::CaseInsensitive); filterModel->setSortCaseSensitivity(Qt::CaseInsensitive);
filterModel->setDynamicSortFilter(true); filterModel->setDynamicSortFilter(true);
filterModel->setSortLocaleAware(true); filterModel->setSortLocaleAware(true);
ui->shortcutsTreeView->setModel(filterModel); ui->shortcutsTreeView->setModel(filterModel);
ui->shortcutsTreeView->header()->setMovable(false); ui->shortcutsTreeView->header()->setSectionsMovable(false);
ui->shortcutsTreeView->sortByColumn(0, Qt::AscendingOrder); ui->shortcutsTreeView->sortByColumn(0, Qt::AscendingOrder);
connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(retranslate())); connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(retranslate()));
connect(ui->shortcutsTreeView->selectionModel(), connect(ui->shortcutsTreeView->selectionModel(),
SIGNAL(currentChanged(QModelIndex,QModelIndex)), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, this,
SLOT(initEditors())); SLOT(initEditors()));
connect(ui->shortcutsTreeView, connect(ui->shortcutsTreeView,
SIGNAL(activated(QModelIndex)), SIGNAL(activated(QModelIndex)),
this, this,
SLOT(switchToEditors(QModelIndex))); SLOT(switchToEditors(QModelIndex)));
connect(ui->lineEditSearch, SIGNAL(textChanged(QString)), connect(ui->lineEditSearch, SIGNAL(textChanged(QString)),
filterModel, SLOT(setFilterFixedString(QString))); filterModel, SLOT(setFilterFixedString(QString)));
// apply button logic // apply button logic
connect(ui->applyButton, SIGNAL(clicked()), this, SLOT(applyChanges( ))); connect(ui->applyButton, SIGNAL(clicked()), this, SLOT(applyChanges( )));
// restore defaults button logic // restore defaults button logic
connect(ui->restoreDefaultsButton, SIGNAL(clicked()), this, SLOT(res toreDefaultShortcuts())); connect(ui->restoreDefaultsButton, SIGNAL(clicked()), this, SLOT(res toreDefaultShortcuts()));
// we need to disable all shortcut actions, so we can enter shortcut s without activating any actions // we need to disable all shortcut actions, so we can enter shortcut s without activating any actions
connect(ui->primaryShortcutEdit, SIGNAL(focusChanged(bool)), shortcu connect(ui->primaryShortcutEdit, SIGNAL(focusChanged(bool)), actionM
tMgr, SLOT(setAllActionsEnabled(bool))); gr, SLOT(setAllActionsEnabled(bool)));
connect(ui->altShortcutEdit, SIGNAL(focusChanged(bool)), shortcutMgr connect(ui->altShortcutEdit, SIGNAL(focusChanged(bool)), actionMgr,
, SLOT(setAllActionsEnabled(bool))); SLOT(setAllActionsEnabled(bool)));
// handling changes in editors // handling changes in editors
connect(ui->primaryShortcutEdit, SIGNAL(contentsChanged()), this, SL OT(handleChanges())); connect(ui->primaryShortcutEdit, SIGNAL(contentsChanged()), this, SL OT(handleChanges()));
connect(ui->altShortcutEdit, SIGNAL(contentsChanged()), this, SLOT(h andleChanges())); connect(ui->altShortcutEdit, SIGNAL(contentsChanged()), this, SLOT(h andleChanges()));
// handle outer shortcuts changes
connect(shortcutMgr, SIGNAL(shortcutChanged(StelShortcut*)), this, S
LOT(updateShortcutsItem(StelShortcut*)));
QString backspaceChar; QString backspaceChar;
backspaceChar.append(QChar(0x232B)); // Erase left backspaceChar.append(QChar(0x232B)); // Erase left
//test.append(QChar(0x2672)); //test.append(QChar(0x2672));
//test.append(QChar(0x267B)); //test.append(QChar(0x267B));
//test.append(QChar(0x267C)); //test.append(QChar(0x267C));
//test.append(QChar(0x21BA)); // Counter-clockwise //test.append(QChar(0x21BA)); // Counter-clockwise
//test.append(QChar(0x2221)); // Angle sign //test.append(QChar(0x2221)); // Angle sign
ui->primaryBackspaceButton->setText(backspaceChar); ui->primaryBackspaceButton->setText(backspaceChar);
ui->altBackspaceButton->setText(backspaceChar); ui->altBackspaceButton->setText(backspaceChar);
skipping to change at line 342 skipping to change at line 340
} }
void ShortcutsDialog::polish() void ShortcutsDialog::polish()
{ {
ui->primaryShortcutEdit->style()->unpolish(ui->primaryShortcutEdit); ui->primaryShortcutEdit->style()->unpolish(ui->primaryShortcutEdit);
ui->primaryShortcutEdit->style()->polish(ui->primaryShortcutEdit); ui->primaryShortcutEdit->style()->polish(ui->primaryShortcutEdit);
ui->altShortcutEdit->style()->unpolish(ui->altShortcutEdit); ui->altShortcutEdit->style()->unpolish(ui->altShortcutEdit);
ui->altShortcutEdit->style()->polish(ui->altShortcutEdit); ui->altShortcutEdit->style()->polish(ui->altShortcutEdit);
} }
QStandardItem* ShortcutsDialog::updateGroup(StelShortcutGroup* group) QStandardItem* ShortcutsDialog::updateGroup(const QString& group)
{ {
QString groupId = group->getId(); QStandardItem* groupItem = findItemByData(QVariant(group),
QStandardItem* groupItem = findItemByData(QVariant(groupId),
Qt::UserRole); Qt::UserRole);
bool isNew = false; bool isNew = false;
if (!groupItem) if (!groupItem)
{ {
// create new // create new
groupItem = new QStandardItem(); groupItem = new QStandardItem();
isNew = true; isNew = true;
} }
// group items aren't selectable, so reset default flag // group items aren't selectable, so reset default flag
groupItem->setFlags(Qt::ItemIsEnabled); groupItem->setFlags(Qt::ItemIsEnabled);
// setup displayed text // setup displayed text
QString groupText = group->getText(); groupItem->setText(q_(group));
QString text(q_(groupText.isEmpty() ? groupId : groupText));
groupItem->setText(text);
// store id // store id
groupItem->setData(groupId, Qt::UserRole); groupItem->setData(group, Qt::UserRole);
groupItem->setColumnCount(3); groupItem->setColumnCount(3);
// setup bold font for group lines // setup bold font for group lines
QFont rootFont = groupItem->font(); QFont rootFont = groupItem->font();
rootFont.setBold(true); rootFont.setBold(true);
rootFont.setPixelSize(14); rootFont.setPixelSize(14);
groupItem->setFont(rootFont); groupItem->setFont(rootFont);
if (isNew) if (isNew)
mainModel->appendRow(groupItem); mainModel->appendRow(groupItem);
// expand only enabled group
bool enabled = group->isEnabled();
QModelIndex index = filterModel->mapFromSource(groupItem->index()); QModelIndex index = filterModel->mapFromSource(groupItem->index());
if (enabled) ui->shortcutsTreeView->expand(index);
ui->shortcutsTreeView->expand(index);
else
ui->shortcutsTreeView->collapse(index);
ui->shortcutsTreeView->setFirstColumnSpanned(index.row(), ui->shortcutsTreeView->setFirstColumnSpanned(index.row(),
QModelIndex(), QModelIndex(),
true); true);
ui->shortcutsTreeView->setRowHidden(index.row(), QModelIndex(), !ena bled); ui->shortcutsTreeView->setRowHidden(index.row(), QModelIndex(), fals e);
return groupItem; return groupItem;
} }
QStandardItem* ShortcutsDialog::findItemByData(QVariant value, int role, in t column) QStandardItem* ShortcutsDialog::findItemByData(QVariant value, int role, in t column)
{ {
for (int row = 0; row < mainModel->rowCount(); row++) for (int row = 0; row < mainModel->rowCount(); row++)
{ {
QStandardItem* item = mainModel->item(row, 0); QStandardItem* item = mainModel->item(row, 0);
if (!item) if (!item)
skipping to change at line 410 skipping to change at line 400
for (int subrow = 0; subrow < item->rowCount(); subrow++) for (int subrow = 0; subrow < item->rowCount(); subrow++)
{ {
QStandardItem* subitem = item->child(subrow, column) ; QStandardItem* subitem = item->child(subrow, column) ;
if (subitem->data(role) == value) if (subitem->data(role) == value)
return subitem; return subitem;
} }
} }
return 0; return 0;
} }
void ShortcutsDialog::updateShortcutsItem(StelShortcut *shortcut, void ShortcutsDialog::updateShortcutsItem(StelAction *action,
QStandardItem *shortcutItem) QStandardItem *shortcutItem)
{ {
QVariant shortcutId(shortcut->getId()); QVariant shortcutId(action->getId());
if (shortcutItem == NULL) if (shortcutItem == NULL)
{ {
// search for item // search for item
shortcutItem = findItemByData(shortcutId, Qt::UserRole, 0); shortcutItem = findItemByData(shortcutId, Qt::UserRole, 0);
} }
// we didn't find item, create and add new // we didn't find item, create and add new
QStandardItem* groupItem = NULL; QStandardItem* groupItem = NULL;
if (shortcutItem == NULL) if (shortcutItem == NULL)
{ {
// firstly search for group // firstly search for group
QVariant groupId(shortcut->getGroup()->getId()); QVariant groupId(action->getGroup());
groupItem = findItemByData(groupId, Qt::UserRole, 0); groupItem = findItemByData(groupId, Qt::UserRole, 0);
if (groupItem == NULL) if (groupItem == NULL)
{ {
// create and add new group to treeWidget // create and add new group to treeWidget
groupItem = updateGroup(shortcut->getGroup()); groupItem = updateGroup(action->getGroup());
} }
// create shortcut item // create shortcut item
shortcutItem = new QStandardItem(); shortcutItem = new QStandardItem();
shortcutItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelecta ble); shortcutItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelecta ble);
groupItem->appendRow(shortcutItem); groupItem->appendRow(shortcutItem);
// store shortcut id, so we can find it when shortcut change d // store shortcut id, so we can find it when shortcut change d
shortcutItem->setData(shortcutId, Qt::UserRole); shortcutItem->setData(shortcutId, Qt::UserRole);
QStandardItem* primaryItem = new QStandardItem(); QStandardItem* primaryItem = new QStandardItem();
QStandardItem* secondaryItem = new QStandardItem(); QStandardItem* secondaryItem = new QStandardItem();
primaryItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectab le); primaryItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectab le);
secondaryItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelect able); secondaryItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelect able);
groupItem->setChild(shortcutItem->row(), 1, primaryItem); groupItem->setChild(shortcutItem->row(), 1, primaryItem);
groupItem->setChild(shortcutItem->row(), 2, secondaryItem); groupItem->setChild(shortcutItem->row(), 2, secondaryItem);
} }
// setup properties of item // setup properties of item
shortcutItem->setText(q_(shortcut->getText())); shortcutItem->setText(action->getText());
QModelIndex index = shortcutItem->index(); QModelIndex index = shortcutItem->index();
mainModel->setData(index.sibling(index.row(), 1), mainModel->setData(index.sibling(index.row(), 1),
shortcut->getPrimaryKey(), Qt::DisplayRole); action->getShortcut(), Qt::DisplayRole);
mainModel->setData(index.sibling(index.row(), 2), mainModel->setData(index.sibling(index.row(), 2),
shortcut->getAltKey(), Qt::DisplayRole); action->getAltShortcut(), Qt::DisplayRole);
} }
void ShortcutsDialog::restoreDefaultShortcuts() void ShortcutsDialog::restoreDefaultShortcuts()
{ {
resetModel(); resetModel();
shortcutMgr->restoreDefaultShortcuts(); actionMgr->restoreDefaultShortcuts();
updateTreeData(); updateTreeData();
initEditors(); initEditors();
} }
void ShortcutsDialog::updateTreeData() void ShortcutsDialog::updateTreeData()
{ {
// Create shortcuts tree // Create shortcuts tree
QList<StelShortcutGroup*> groups = shortcutMgr->getGroupList(); QStringList groups = actionMgr->getGroupList();
foreach (StelShortcutGroup* group, groups) foreach (const QString& group, groups)
{ {
updateGroup(group); updateGroup(group);
// display group's shortcuts // display group's shortcuts
QList<StelShortcut*> shortcuts = group->getActionList(); QList<StelAction*> actions = actionMgr->getActionList(group)
foreach (StelShortcut* shortcut, shortcuts) ;
foreach (StelAction* action, actions)
{ {
updateShortcutsItem(shortcut); updateShortcutsItem(action);
} }
} }
updateText(); updateText();
} }
bool ShortcutsDialog::itemIsEditable(QStandardItem *item) bool ShortcutsDialog::itemIsEditable(QStandardItem *item)
{ {
if (item == NULL) return false; if (item == NULL) return false;
// non-editable items(not group items) have no Qt::ItemIsSelectable flag // non-editable items(not group items) have no Qt::ItemIsSelectable flag
return (Qt::ItemIsSelectable & item->flags()); return (Qt::ItemIsSelectable & item->flags());
 End of changes. 30 change blocks. 
52 lines changed or deleted 40 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/