summaryrefslogtreecommitdiff
path: root/muse2/muse/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'muse2/muse/widgets')
-rw-r--r--muse2/muse/widgets/shortcutconfig.cpp134
-rw-r--r--muse2/muse/widgets/shortcutconfig.h15
-rw-r--r--muse2/muse/widgets/shortcutconfigbase.ui38
3 files changed, 174 insertions, 13 deletions
diff --git a/muse2/muse/widgets/shortcutconfig.cpp b/muse2/muse/widgets/shortcutconfig.cpp
index 609564cc..a2e16d17 100644
--- a/muse2/muse/widgets/shortcutconfig.cpp
+++ b/muse2/muse/widgets/shortcutconfig.cpp
@@ -31,11 +31,18 @@
// Description:
// Dialog for configuring keyboard shortcuts
+#include "config.h"
+
#include <QCloseEvent>
#include <QKeySequence>
#include <QString>
#include <QSettings>
#include <QApplication>
+#include <QFileDialog>
+#include <QDir>
+#include <QFile>
+#include <QMessageBox>
+#include <QString>
#include "shortcutconfig.h"
#include "shortcutcapturedialog.h"
@@ -54,10 +61,13 @@ ShortcutConfig::ShortcutConfig(QWidget* parent)
this, SLOT(categorySelChanged(QTreeWidgetItem*, int)));
connect(scListView, SIGNAL(itemActivated(QTreeWidgetItem*, int )),
this, SLOT(shortcutSelChanged(QTreeWidgetItem*, int)));
-
+
+ okButton->setDefault(true);
connect(defineButton, SIGNAL(pressed()), this, SLOT(assignShortcut()));
connect(clearButton, SIGNAL(pressed()), this, SLOT(clearShortcut()));
- connect(applyButton, SIGNAL(pressed()), this, SLOT(assignAll()));
+ connect(textFileButton, SIGNAL(pressed()), this, SLOT(textFileClicked()));
+ connect(applyButton, SIGNAL(pressed()), this, SLOT(applyAll()));
+ connect(okButton, SIGNAL(pressed()), this, SLOT(okClicked()));
current_category = ALL_SHRT;
cgListView->sortItems(SHRT_CATEGORY_COL, Qt::AscendingOrder);
@@ -110,8 +120,8 @@ void ShortcutConfig::assignShortcut()
QKeySequence keySequence = QKeySequence(key);
active->setText(SHRT_SHRTCUT_COL, keySequence);
_config_changed = true;
+ clearButton->setEnabled(true);
}
- clearButton->setEnabled(true);
defineButton->setDown(false);
}
@@ -146,16 +156,124 @@ void ShortcutConfig::shortcutSelChanged(QTreeWidgetItem* in_item, int /*column*/
void ShortcutConfig::closeEvent(QCloseEvent* /*e*/) // prevent compiler warning : unused variable
{
- QSettings settings("MusE", "MusE-qt");
- settings.setValue("ShortcutConfig/geometry", saveGeometry());
- done(_config_changed);
+ closing();
}
+// NOTE: closeEvent was not being called when Esc was pressed, despite the implication that
+// it should in the Qt help ("close event can't be ignored"). So this is a workaround,
+// and the 'recommended' way according to forums.
+void ShortcutConfig::reject()
+ {
+ closing();
+ QDialog::reject();
+ }
-void ShortcutConfig::assignAll()
+void ShortcutConfig::closing()
+{
+ QSettings settings("MusE", "MusE-qt");
+ settings.setValue("ShortcutConfig/geometry", saveGeometry());
+ if(_config_changed)
+ {
+ emit saveConfig();
+ _config_changed = false;
+ }
+}
+
+void ShortcutConfig::applyAll()
{
applyButton->setDown(false);
- done(_config_changed);
+ closing(); // Just call closing to store everything, and don't close.
}
+void ShortcutConfig::okClicked()
+ {
+ okButton->setDown(false);
+ close();
+ }
+
+void ShortcutConfig::textFileClicked()
+{
+ textFileButton->setDown(false);
+
+ QString fname = QFileDialog::getSaveFileName(this,
+ tr("Save printable text file"),
+ QDir::homePath() + "/shortcuts.txt",
+ tr("Text files (*.txt);;All files (*)"));
+ if(fname.isEmpty())
+ {
+ //QMessageBox::critical(this, tr("Error"), tr("Selected file name is empty"));
+ return;
+ }
+
+ QFile qf(fname);
+ if(!qf.open(QIODevice::WriteOnly | QIODevice::Text))
+ {
+ QMessageBox::critical(this, tr("Error"), tr("Error opening file for saving"));
+ return;
+ }
+
+ bool error = false;
+
+ QString header;
+ for (int i=0; i < SHRT_NUM_OF_CATEGORIES; i++)
+ {
+ if(shortcut_category[i].id_flag == current_category)
+ {
+ header = QString(PACKAGE_NAME) + " " + tr("Shortcuts for selected category: ") + QString(shortcut_category[i].name) + "\n\n";
+ break;
+ }
+ }
+ if(!header.isEmpty() && qf.write(header.toLatin1().constData()) == -1)
+ error = true;
+
+ QString info;
+ if(current_category == ALL_SHRT)
+ {
+ info = tr("Legend:\n");
+ for (int i=0; i < SHRT_NUM_OF_CATEGORIES; i++)
+ {
+ if(shortcut_category[i].id_flag == ALL_SHRT)
+ continue;
+ info += (QString::number(i) + " : " + QString(shortcut_category[i].name) + "\n");
+ }
+ info += "\n";
+ }
+ if(!info.isEmpty() && qf.write(info.toLatin1().constData()) == -1)
+ error = true;
+
+ for(int i=0; i < SHRT_NUM_OF_ELEMENTS; i++)
+ {
+ if(shortcuts[i].type & current_category)
+ {
+ QString s;
+ int pos = 0;
+ if(current_category == ALL_SHRT)
+ {
+ for(int j=0; j < SHRT_NUM_OF_CATEGORIES; j++)
+ {
+ if(shortcut_category[j].id_flag == ALL_SHRT)
+ continue;
+ if(shortcuts[i].type & shortcut_category[j].id_flag)
+ s.insert(pos, QString::number(j));
+ pos += 3;
+ }
+ s.insert(pos, " : ");
+ pos += 3;
+ }
+
+ s.insert(pos, QKeySequence(shortcuts[i].key).toString());
+ pos += 25;
+ s.insert(pos, qApp->translate("shortcuts", shortcuts[i].descr) + "\n");
+ if(qf.write(s.toLatin1().constData()) == -1)
+ error = true;
+ }
+ }
+
+ qf.close();
+
+ if(error)
+ QMessageBox::critical(this, tr("Error"), tr("An error occurred while saving"));
+}
+
+
} // namespace MusEGui
diff --git a/muse2/muse/widgets/shortcutconfig.h b/muse2/muse/widgets/shortcutconfig.h
index 3faf2b5e..d3f189e4 100644
--- a/muse2/muse/widgets/shortcutconfig.h
+++ b/muse2/muse/widgets/shortcutconfig.h
@@ -68,17 +68,24 @@ class ShortcutConfig : public QDialog, public Ui::ShortcutConfigBase {
void updateSCListView(int category);
void updateSCListView() { updateSCListView(current_category); }
void closeEvent(QCloseEvent *e);
+ void closing();
private slots:
void categorySelChanged(QTreeWidgetItem*, int);
void shortcutSelChanged(QTreeWidgetItem*, int);
void assignShortcut();
void clearShortcut();
- void assignAll();
-
-
+ void applyAll();
+ void okClicked();
+ void textFileClicked();
+
+ protected:
+ void reject();
+ signals:
+ void saveConfig();
+
public:
- ShortcutConfig(QWidget* parent);
+ ShortcutConfig(QWidget* parent = 0);
bool _config_changed;
};
diff --git a/muse2/muse/widgets/shortcutconfigbase.ui b/muse2/muse/widgets/shortcutconfigbase.ui
index 6dd5d5b7..da62ed19 100644
--- a/muse2/muse/widgets/shortcutconfigbase.ui
+++ b/muse2/muse/widgets/shortcutconfigbase.ui
@@ -29,7 +29,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="childrenCollapsible">
- <bool>false</bool>
+ <bool>true</bool>
</property>
<widget class="QTreeWidget" name="cgListView">
<property name="sizePolicy">
@@ -146,6 +146,42 @@
</property>
</widget>
</item>
+ <item>
+ <widget class="QPushButton" name="textFileButton">
+ <property name="text">
+ <string>&amp;Printable file...</string>
+ </property>
+ <property name="shortcut">
+ <string>Alt+P</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="spacer4">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Expanding</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>30</width>
+ <height>21</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="okButton">
+ <property name="text">
+ <string>&amp;Ok</string>
+ </property>
+ <property name="shortcut">
+ <string>Alt+O</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
</layout>