diff --git a/NEWS.md b/NEWS.md index 03179dad..54911375 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +Red Panda C++ Version 1.0.3 + - fix: when oj problem grabbed by competitive companion received, + the app is restored to normal state, no matter it's current state. + - enhancement: input shortcut in the option dialog's general -> shortcut page by pressing keys. + Red Panda C++ Version 1.0.2 - enhancement: press tab in column mode won't exit column mode - enhancement: refine behavior of undo input space char diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 52962611..7ceaec13 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -10,7 +10,7 @@ isEmpty(APP_NAME) { } isEmpty(APP_VERSION) { - APP_VERSION=1.0.2 + APP_VERSION=1.0.3 } @@ -181,6 +181,7 @@ SOURCES += \ widgets/qpatchedcombobox.cpp \ widgets/searchdialog.cpp \ widgets/searchresultview.cpp \ + widgets/shortcutinputedit.cpp \ widgets/signalmessagedialog.cpp HEADERS += \ @@ -326,6 +327,7 @@ HEADERS += \ widgets/qpatchedcombobox.h \ widgets/searchdialog.h \ widgets/searchresultview.h \ + widgets/shortcutinputedit.h \ widgets/signalmessagedialog.h FORMS += \ diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 40c4dfa7..faf4fe64 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -3309,7 +3309,8 @@ void MainWindow::onNewProblemConnection() ui->lstProblemSet->setCurrentIndex(mOJProblemSetModel.index( mOJProblemSetModel.count()-1 ,0)); - showNormal(); + if (isMinimized()) + showNormal(); raise(); // for mac OS? activateWindow(); } diff --git a/RedPandaIDE/settingsdialog/environmentshortcutwidget.cpp b/RedPandaIDE/settingsdialog/environmentshortcutwidget.cpp index d0cb097b..a2a12d26 100644 --- a/RedPandaIDE/settingsdialog/environmentshortcutwidget.cpp +++ b/RedPandaIDE/settingsdialog/environmentshortcutwidget.cpp @@ -17,6 +17,7 @@ #include "environmentshortcutwidget.h" #include "ui_environmentshortcutwidget.h" #include "../mainwindow.h" +#include "../widgets/shortcutinputedit.h" #include EnvironmentShortcutWidget::EnvironmentShortcutWidget(const QString& name, const QString& group, QWidget *parent) : @@ -24,9 +25,12 @@ EnvironmentShortcutWidget::EnvironmentShortcutWidget(const QString& name, const ui(new Ui::EnvironmentShortcutWidget) { ui->setupUi(this); + mDelegate =new EnvironmentShortcutDelegate(this); ui->tblShortcut->setModel(&mModel); + ui->tblShortcut->setItemDelegate(mDelegate); connect(&mModel, &EnvironmentShortcutModel::shortcutChanged, this, &SettingsWidget::setSettingsChanged); + mDelegate =new EnvironmentShortcutDelegate(this); } EnvironmentShortcutWidget::~EnvironmentShortcutWidget() @@ -92,7 +96,7 @@ QVariant EnvironmentShortcutModel::data(const QModelIndex &index, int role) cons if (!index.isValid()) { return QVariant(); } - if (role==Qt::DisplayRole || role == Qt::EditRole) { + if (role==Qt::DisplayRole || role == Qt::EditRole || role == Qt::ToolTipRole) { PEnvironmentShortcut item = mShortcuts[index.row()]; switch( index.column()) { case 0: @@ -173,3 +177,25 @@ void EnvironmentShortcutModel::loadShortCutsOfMenu(const QMenu *menu, QList(parent)); + connect(editor,&ShortcutInputEdit::inputFinished, + this, &EnvironmentShortcutDelegate::onEditingFinished); + return editor; + } + return QStyledItemDelegate::createEditor(parent,option,index); +} + +void EnvironmentShortcutDelegate::onEditingFinished(QWidget* editor) +{ + emit commitData(editor); + emit closeEditor(editor, QAbstractItemDelegate::SubmitModelCache); +} diff --git a/RedPandaIDE/settingsdialog/environmentshortcutwidget.h b/RedPandaIDE/settingsdialog/environmentshortcutwidget.h index ba5d164b..d0244925 100644 --- a/RedPandaIDE/settingsdialog/environmentshortcutwidget.h +++ b/RedPandaIDE/settingsdialog/environmentshortcutwidget.h @@ -18,6 +18,7 @@ #define ENVIRONMENTSHORTCUTWIDGET_H #include +#include #include #include "settingswidget.h" #include "../shortcutmanager.h" @@ -49,6 +50,18 @@ private: void loadShortCutsOfMenu(const QMenu * menu, QList& globalActions); private: QList mShortcuts; + +}; + +class EnvironmentShortcutDelegate: public QStyledItemDelegate { + Q_OBJECT +public: + explicit EnvironmentShortcutDelegate(QObject *parent = nullptr); + +public: + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; +protected slots: + void onEditingFinished(QWidget* editor); }; class EnvironmentShortcutWidget : public SettingsWidget @@ -68,6 +81,7 @@ protected: void doSave() override; private: EnvironmentShortcutModel mModel; + EnvironmentShortcutDelegate* mDelegate; }; #endif // ENVIRONMENTSHORTCUTWIDGET_H diff --git a/RedPandaIDE/settingsdialog/environmentshortcutwidget.ui b/RedPandaIDE/settingsdialog/environmentshortcutwidget.ui index 5b1854b9..2d584d1b 100644 --- a/RedPandaIDE/settingsdialog/environmentshortcutwidget.ui +++ b/RedPandaIDE/settingsdialog/environmentshortcutwidget.ui @@ -19,6 +19,9 @@ true + + 250 + true diff --git a/RedPandaIDE/widgets/shortcutinputedit.cpp b/RedPandaIDE/widgets/shortcutinputedit.cpp new file mode 100644 index 00000000..9c884a53 --- /dev/null +++ b/RedPandaIDE/widgets/shortcutinputedit.cpp @@ -0,0 +1,54 @@ +#include "shortcutinputedit.h" + +#include +#include +#include +#include + +ShortcutInputEdit::ShortcutInputEdit(QWidget* parent):QLineEdit(parent) +{ + QList acts = actions(); + foreach (const QAction* action, acts) { + qDebug()<shortcut()[0]; + } +} + +void ShortcutInputEdit::keyPressEvent(QKeyEvent *event) +{ + if (event->key()==Qt::Key_Delete && event->modifiers()==Qt::NoModifier) { + setText(""); + } else if (event->key()==Qt::Key_Backspace && event->modifiers()==Qt::NoModifier) { + setText(""); + } else if (event->key()==Qt::Key_Control || + event->key()==Qt::Key_Alt || + event->key()==Qt::Key_Shift || + event->key()==Qt::Key_Meta + ) { + QKeySequence seq(event->modifiers()); + setText(""); + } else { + int key = event->key(); + if (key==Qt::Key_Backtab) + key = Qt::Key_Tab; + QKeySequence seq(event->modifiers()|key); + setText(seq.toString()); + if (key!=Qt::Key_Tab + && key!=Qt::Key_Enter + && key!=Qt::Key_Return) + emit inputFinished(this); + } + event->accept(); +} + +bool ShortcutInputEdit::event(QEvent *event) +{ + if (event->type()==QEvent::ShortcutOverride) { + keyPressEvent((QKeyEvent*)event); + event->accept(); + return true; + } else if (event->type()==QEvent::KeyPress) { + keyPressEvent((QKeyEvent*)event); + return true; + } + return QLineEdit::event(event); +} diff --git a/RedPandaIDE/widgets/shortcutinputedit.h b/RedPandaIDE/widgets/shortcutinputedit.h new file mode 100644 index 00000000..460e18b8 --- /dev/null +++ b/RedPandaIDE/widgets/shortcutinputedit.h @@ -0,0 +1,22 @@ +#ifndef SHORTCUTINPUTEDIT_H +#define SHORTCUTINPUTEDIT_H + +#include + +class ShortcutInputEdit : public QLineEdit +{ + Q_OBJECT +public: + ShortcutInputEdit(QWidget* parent); +signals: + void inputFinished(QWidget* editor); + // QWidget interface +protected: + void keyPressEvent(QKeyEvent *event) override; + + // QObject interface +public: + bool event(QEvent *event) override; +}; + +#endif // SHORTCUTINPUTEDIT_H diff --git a/Red_Panda_CPP.pro b/Red_Panda_CPP.pro index 72f2f36c..bd1d92a5 100644 --- a/Red_Panda_CPP.pro +++ b/Red_Panda_CPP.pro @@ -17,7 +17,7 @@ SUBDIRS += \ APP_NAME = RedPandaCPP -APP_VERSION = 1.0.2 +APP_VERSION = 1.0.3 linux: {