17#include "shortcutspage.h"
18#include "ui_shortcutspage.h"
22#include <QStandardItemModel>
24#include <QKeySequence>
26#include "pencilsettings.h"
31static const int ACT_NAME_COLUMN = 0;
32static const int KEY_SEQ_COLUMN = 1;
36ShortcutsPage::ShortcutsPage(
QWidget* parent )
42 m_treeModel->setColumnCount(2);
43 m_treeModel->setHorizontalHeaderLabels({ tr(
"Action",
"Shortcut table header"), tr(
"Shortcut",
"Shortcut table header") });
44 treeModelLoadShortcutsSetting();
46 ui->treeView->setModel(m_treeModel);
47 ui->treeView->resizeColumnToContents(0);
51 connect( ui->restoreShortcutsButton, &
QPushButton::clicked,
this, &ShortcutsPage::restoreShortcutsButtonClicked );
52 connect(ui->btnSaveShortcuts, &
QPushButton::clicked,
this, &ShortcutsPage::saveShortcutsButtonClicked);
53 connect(ui->btnLoadShortcuts, &
QPushButton::clicked,
this, &ShortcutsPage::loadShortcutsButtonClicked);
57 tableItemClicked(m_treeModel->index(0, 0));
60ShortcutsPage::~ShortcutsPage() {
64void ShortcutsPage::tableItemClicked(
const QModelIndex& modelIndex )
66 int row = modelIndex.
row();
70 ui->actionNameLabel->setText(actionItem->
text());
74 ui->keySequenceEdit->setKeySequence(keySeqItem->
text());
76 qDebug() <<
"Command Selected:" << actionItem->
text();
78 m_currentItemIndex = modelIndex;
80 ui->keySequenceEdit->setFocus();
83void ShortcutsPage::keyCapLineEditTextChanged()
86 if (!m_currentItemIndex.
isValid())
91 int row = m_currentItemIndex.
row();
99 setting.beginGroup(
"shortcuts");
101 if (isKeySequenceExist(setting, strCmdName, keySequence))
104 msgBox.setText(
tr(
"Shortcut Conflict!"));
110 int result = msgBox.exec();
114 ui->keySequenceEdit->setKeySequence( keySeqItem->
text() );
117 removeDuplicateKeySequence(&setting, keySequence);
120 setting.setValue(strCmdName, strKeySeq);
124 treeModelLoadShortcutsSetting();
126 qDebug() <<
"Shortcut " << strCmdName <<
" = " << strKeySeq;
129void ShortcutsPage::saveShortcutsButtonClicked()
131 QSettings settings( PENCIL2D, PENCIL2D );
132 settings.beginGroup(
"LastSavePath" );
134 QString fDir = settings.value(
"Shortcuts").toString();
139 tr(
"Save Pencil2D Shortcut file"),
140 fDir +
"/" +
tr(
"untitled.pcls"),
141 tr(
"Pencil2D Shortcut File(*.pcls)"));
142 settings.setValue(
"Shortcuts", fileName);
146 settings.beginGroup(
"shortcuts" );
147 out.beginGroup(
"shortcuts");
149 foreach (
QString key, settings.allKeys())
151 out.setValue(key, settings.value(key));
155void ShortcutsPage::loadShortcutsButtonClicked()
157 QSettings settings( PENCIL2D, PENCIL2D );
158 settings.beginGroup(
"LastSavePath");
159 QString fDir = settings.value(
"Shortcuts").toString();
165 tr(
"Open Pencil2D Shortcut file"),
167 tr(
"Pencil2D Shortcut File(*.pcls)"));
171 qDebug() <<
"Shortcut file not readable";
176 if (input.status() !=
QSettings::NoError || !input.childGroups().contains(
"shortcuts"))
178 qDebug() <<
"Error accessing or parsing shortcut file" << input.status();
182 input.beginGroup(
"shortcuts");
183 settings.beginGroup(
"shortcuts");
184 foreach (
QString pShortcutsKey, input.allKeys())
186 settings.setValue(pShortcutsKey, input.value(pShortcutsKey));
189 treeModelLoadShortcutsSetting();
192void ShortcutsPage::restoreShortcutsButtonClicked()
194 restoreShortcutsToDefault();
195 treeModelLoadShortcutsSetting();
202 if (strTargetCmdName == strCmdName)
229void ShortcutsPage::treeModelLoadShortcutsSetting()
232 QSettings settings( PENCIL2D, PENCIL2D );
241 const QString &strShortcutName = getHumanReadableShortcutName(strCmdName);
242 if (strShortcutName.
isEmpty()) {
252 if (m_treeModel->
item(row , ACT_NAME_COLUMN) ==
nullptr)
254 if (m_treeModel->
item(row, KEY_SEQ_COLUMN) ==
nullptr)
257 m_treeModel->
item(row, ACT_NAME_COLUMN)->
setData(strCmdName);
258 m_treeModel->
item(row, ACT_NAME_COLUMN)->
setText(strShortcutName);
260 m_treeModel->
item(row, KEY_SEQ_COLUMN)->
setText(strKeySequence);
268 ui->treeView->resizeColumnToContents( 0 );
271void ShortcutsPage::clearButtonClicked()
273 if ( !m_currentItemIndex.
isValid() )
278 int row = m_currentItemIndex.
row();
284 setting.setValue( strCmdName,
"" );
287 ui->keySequenceEdit->clear();
289 treeModelLoadShortcutsSetting();
298static QString getHumanReadableShortcutName(
const QString& cmdName)
304 {CMD_PASTE_FROM_PREVIOUS,
ShortcutsPage::tr(
"Paste from Previous Keyframe",
"Shortcut")},
322 {CMD_SELECTION_FLIP_HORIZONTAL,
ShortcutsPage::tr(
"Selection: Horizontal Flip",
"Shortcut")},
323 {CMD_SELECTION_FLIP_VERTICAL,
ShortcutsPage::tr(
"Selection: Vertical Flip",
"Shortcut")},
325 {CMD_SELECTION_REPOSITION_FRAMES,
ShortcutsPage::tr(
"Selection: Reposition Frames",
"Shortcut")},
326 {CMD_SELECTION_ADD_FRAME_EXPOSURE,
ShortcutsPage::tr(
"Selection: Add Frame Exposure",
"Shortcut")},
327 {CMD_SELECTION_SUBTRACT_FRAME_EXPOSURE,
ShortcutsPage::tr(
"Selection: Subtract Frame Exposure",
"Shortcut")},
328 {CMD_REVERSE_SELECTED_FRAMES,
ShortcutsPage::tr(
"Selection: Reverse Keyframes",
"Shortcut")},
329 {CMD_REMOVE_SELECTED_FRAMES,
ShortcutsPage::tr(
"Selection: Remove Keyframes",
"Shortcut")},
333 {CMD_OVERLAY_GOLDEN_RATIO,
ShortcutsPage::tr(
"Toggle Golden Ratio Overlay",
"Shortcut")},
334 {CMD_OVERLAY_SAFE_AREAS,
ShortcutsPage::tr(
"Toggle Safe Areas Overlay",
"Shortcut")},
335 {CMD_OVERLAY_ONE_POINT_PERSPECTIVE,
ShortcutsPage::tr(
"Toggle One Point Perspective Overlay",
"Shortcut")},
336 {CMD_OVERLAY_TWO_POINT_PERSPECTIVE,
ShortcutsPage::tr(
"Toggle Two Point Perspective Overlay",
"Shortcut")},
337 {CMD_OVERLAY_THREE_POINT_PERSPECTIVE,
ShortcutsPage::tr(
"Toggle Three Point Perspective Overlay",
"Shortcut")},
340 {CMD_IMPORT_IMAGE_PREDEFINED_SET,
ShortcutsPage::tr(
"Import Image Predefined Set",
"Shortcut")},
343 {CMD_IMPORT_ANIMATED_IMAGE,
ShortcutsPage::tr(
"Import Animated Image",
"Shortcut")},
344 {CMD_IMPORT_LAYERS,
ShortcutsPage::tr(
"Import Layers from project file",
"Shortcut")},
346 {CMD_IMPORT_PALETTE_REPLACE,
ShortcutsPage::tr(
"Import Palette (Replace)",
"Shortcut")},
349 {CMD_CURRENT_LAYER_VISIBILITY,
ShortcutsPage::tr(
"Show Current Layer Only",
"Shortcut")},
350 {CMD_RELATIVE_LAYER_VISIBILITY,
ShortcutsPage::tr(
"Show Layers Relative to Current Layer",
"Shortcut")},
361 {CMD_ONIONSKIN_PREV,
ShortcutsPage::tr(
"Toggle Previous Onion Skin",
"Shortcut")},
379 {CMD_TOGGLE_STATUS_BAR,
ShortcutsPage::tr(
"Toggle Status Bar Visibility",
"Shortcut")},
380 {CMD_TOGGLE_COLOR_INSPECTOR,
ShortcutsPage::tr(
"Toggle Color Inspector Window Visibility",
"Shortcut")},
381 {CMD_TOGGLE_COLOR_LIBRARY,
ShortcutsPage::tr(
"Toggle Color Palette Window Visibility",
"Shortcut")},
382 {CMD_TOGGLE_COLOR_WHEEL,
ShortcutsPage::tr(
"Toggle Color Box Window Visibility",
"Shortcut")},
383 {CMD_TOGGLE_ONION_SKIN,
ShortcutsPage::tr(
"Toggle Onion Skins Window Visibility",
"Shortcut")},
384 {CMD_TOGGLE_TIMELINE,
ShortcutsPage::tr(
"Toggle Timeline Window Visibility",
"Shortcut")},
385 {CMD_TOGGLE_TOOLBOX,
ShortcutsPage::tr(
"Toggle Tools Window Visibility",
"Shortcut")},
386 {CMD_TOGGLE_TOOL_OPTIONS,
ShortcutsPage::tr(
"Toggle Options Window Visibility",
"Shortcut")},
398 {CMD_RESET_ALL_TOOLS,
ShortcutsPage::tr(
"Reset all tools to default",
"Shortcut")},
399 {CMD_CHANGE_LINE_COLOR_KEYFRAME,
ShortcutsPage::tr(
"Change Line Color (Current keyframe)",
"Shortcut")},
400 {CMD_CHANGE_LINE_COLOR_LAYER,
ShortcutsPage::tr(
"Change Line Color (All keyframes on layer)",
"Shortcut")},
401 {CMD_CHANGE_LAYER_OPACITY,
ShortcutsPage::tr(
"Change Layer / Keyframe Opacity",
"Shortcut")},
403 {CMD_REMOVE_LAST_POLYLINE_SEGMENT,
ShortcutsPage::tr(
"Remove Last Polyline Segment",
"Shortcut")},
415 return humanReadableShortcutNames.
value(cmdName,
QString());
void clicked(const QModelIndex &index)
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
const T value(const Key &key) const const
QString toString(QKeySequence::SequenceFormat format) const const
bool isValid() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QStringList allKeys() const const
void beginGroup(const QString &prefix)
void setValue(const QString &key, const QVariant &value)
QVariant value(const QString &key, const QVariant &defaultValue) const const
virtual QVariant data(int role) const const
virtual void setData(const QVariant &value, int role)
void setEditable(bool editable)
void setText(const QString &text)
QString text() const const
virtual int columnCount(const QModelIndex &parent) const const override
QStandardItem * item(int row, int column) const const
void setItem(int row, int column, QStandardItem *item)
void setRowCount(int rows)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isEmpty() const const
void keySequence(QWindow *window, const QKeySequence &keySequence)
QString toString() const const