diff --git a/include/SettingsManager.hpp b/include/SettingsManager.hpp index 6aff8113e..a8462f158 100644 --- a/include/SettingsManager.hpp +++ b/include/SettingsManager.hpp @@ -29,6 +29,12 @@ namespace Settings { +enum ViewMode{ + FULL_EDITOR, + FULL_IO, + SPLIT +}; + struct SettingsData { int companionPort; @@ -74,6 +80,9 @@ struct SettingsData QKeySequence hotkeyCompileRun; QKeySequence hotkeyFormat; QKeySequence hotkeyKill; + QKeySequence hotkeyViewModeToggler; + + ViewMode viewMode; }; class SettingManager @@ -162,6 +171,9 @@ class SettingManager bool isCheckUpdateOnStartup(); void checkUpdateOnStartup(bool value); + ViewMode getViewMode(); + void setViewMode(ViewMode v); + SettingsData toData(); ~SettingManager(); @@ -170,11 +182,14 @@ class SettingManager void setHotkeyCompileRun(QKeySequence sequence); void setHotkeyRun(QKeySequence sequence); void setHotkeyCompile(QKeySequence sequence); + void setHotkeyViewModeToggler(QKeySequence sequence); QKeySequence getHotkeyFormat(); QKeySequence getHotkeyKill(); QKeySequence getHotkeyCompileRun(); QKeySequence getHotkeyRun(); QKeySequence getHotkeyCompile(); + QKeySequence getHotkeyViewModeToggler(); + private: QString mSettingsFile; diff --git a/include/appwindow.hpp b/include/appwindow.hpp index 0e3b7f976..0b7512fc9 100644 --- a/include/appwindow.hpp +++ b/include/appwindow.hpp @@ -58,6 +58,7 @@ class AppWindow : public QMainWindow void onSettingsApplied(); void onSplitterMoved(int, int); void onIncomingCompanionRequest(Network::CompanionData); + void onViewModeToggle(); void on_actionCompile_triggered(); @@ -71,7 +72,13 @@ class AppWindow : public QMainWindow void on_actionKill_Processes_triggered(); - private: + void on_actionEditor_Mode_triggered(); + + void on_actionIO_Mode_triggered(); + + void on_actionSplit_Mode_triggered(); + +private: Ui::AppWindow *ui; MessageLogger *activeLogger = nullptr; QTimer *timer = nullptr; diff --git a/src/SettingsManager.cpp b/src/SettingsManager.cpp index 29a406012..c7d047ae1 100644 --- a/src/SettingsManager.cpp +++ b/src/SettingsManager.cpp @@ -342,6 +342,14 @@ QKeySequence SettingManager::getHotkeyFormat() { return QKeySequence::fromString(mSettings->value("hotkey_format", "").toString()); } +QKeySequence SettingManager::getHotkeyViewModeToggler() +{ + return QKeySequence::fromString(mSettings->value("hotkey_mode_toggle", "").toString()); +} +void SettingManager::setHotkeyViewModeToggler(QKeySequence sequence) +{ + mSettings->setValue("hotkey_mode_toggle", sequence.toString()); +} void SettingManager::setHotkeyCompile(QKeySequence sequence) { mSettings->setValue("hotkey_compile", sequence.toString()); @@ -363,6 +371,23 @@ void SettingManager::setHotkeyFormat(QKeySequence sequence) mSettings->setValue("hotkey_format", sequence.toString()); } +ViewMode SettingManager::getViewMode() +{ + QString strings = mSettings->value("view_mode", "split").toString(); + if(strings == "split") return Settings::ViewMode::SPLIT; + else if(strings == "code") return Settings::ViewMode::FULL_EDITOR; + else return Settings::ViewMode::FULL_IO; +} + +void SettingManager::setViewMode(ViewMode v) +{ + QString ans; + if(v == Settings::FULL_EDITOR) ans = "code"; + else if(v == Settings::FULL_IO) ans = "io"; + else ans = "split"; + mSettings->setValue("view_mode", ans); +} + SettingManager::~SettingManager() { mSettings->sync(); @@ -406,6 +431,8 @@ SettingsData SettingManager::toData() data.hotkeyCompileRun = getHotkeyCompileRun(); data.hotkeyKill = getHotkeyKill(); data.hotkeyFormat = getHotkeyFormat(); + data.hotkeyViewModeToggler = getHotkeyViewModeToggler(); + data.viewMode = getViewMode(); return data; } diff --git a/src/appwindow.cpp b/src/appwindow.cpp index 144a17b54..845a46815 100644 --- a/src/appwindow.cpp +++ b/src/appwindow.cpp @@ -138,6 +138,21 @@ void AppWindow::allocate() void AppWindow::applySettings() { ui->actionAutosave->setChecked(settingManager->isAutoSave()); + Settings::ViewMode mode = settingManager->getViewMode(); + + + switch(mode) + { + case Settings::ViewMode::FULL_EDITOR : + on_actionEditor_Mode_triggered(); + break; + case Settings::ViewMode::FULL_IO : + on_actionIO_Mode_triggered(); + break; + case Settings::ViewMode::SPLIT : + on_actionSplit_Mode_triggered(); + } + if (settingManager->isAutoSave()) timer->start(); @@ -188,6 +203,11 @@ void AppWindow::maybeSetHotkeys() hotkeyObjects.push_back( new QShortcut(settingManager->getHotkeyKill(), this, SLOT(on_actionKill_Processes_triggered()))); } + if(!settingManager->getHotkeyViewModeToggler().isEmpty()) + { + hotkeyObjects.push_back( + new QShortcut(settingManager->getHotkeyViewModeToggler(), this, SLOT(onViewModeToggle()))); + } } void AppWindow::saveSettings() @@ -435,6 +455,25 @@ void AppWindow::onIncomingCompanionRequest(Network::CompanionData data) ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); } +void AppWindow::onViewModeToggle(){ + if(ui->actionEditor_Mode->isChecked()) + { + on_actionIO_Mode_triggered(); + return ; + } + if(ui->actionSplit_Mode->isChecked()) + { + on_actionEditor_Mode_triggered(); + return ; + } + if(ui->actionIO_Mode->isChecked()) + { + on_actionSplit_Mode_triggered(); + return ; + } + +} + void AppWindow::onSplitterMoved(int _, int __) { int current = ui->tabWidget->currentIndex(); @@ -489,3 +528,30 @@ void AppWindow::on_actionKill_Processes_triggered() auto tmp = dynamic_cast(ui->tabWidget->widget(current)); tmp->killProcesses(); } + +void AppWindow::on_actionEditor_Mode_triggered() +{ + settingManager->setViewMode(Settings::ViewMode::FULL_EDITOR); + ui->actionEditor_Mode->setChecked(true); + ui->actionIO_Mode->setChecked(false); + ui->actionSplit_Mode->setChecked(false); + onTabChanged(ui->tabWidget->currentIndex()); +} + +void AppWindow::on_actionIO_Mode_triggered() +{ + settingManager->setViewMode(Settings::ViewMode::FULL_IO); + ui->actionEditor_Mode->setChecked(false); + ui->actionIO_Mode->setChecked(true); + ui->actionSplit_Mode->setChecked(false); + onTabChanged(ui->tabWidget->currentIndex()); +} + +void AppWindow::on_actionSplit_Mode_triggered() +{ + settingManager->setViewMode(Settings::ViewMode::SPLIT); + ui->actionEditor_Mode->setChecked(false); + ui->actionIO_Mode->setChecked(false); + ui->actionSplit_Mode->setChecked(true); + onTabChanged(ui->tabWidget->currentIndex()); +} diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 5a254fb57..21dedde75 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -367,7 +367,22 @@ void MainWindow::setSettingsData(Settings::SettingsData data) else editor->setWordWrapMode(QTextOption::NoWrap); - // TODO Update some commands; + if(data.viewMode == Settings::ViewMode::FULL_EDITOR) + { + ui->splitter->restoreState(""); + ui->splitter->setSizes({1,0}); + } + else if(data.viewMode == Settings::ViewMode::FULL_IO) + { + ui->splitter->restoreState(""); + ui->splitter->setSizes({0,1}); + } + else + { + ui->splitter->restoreState(""); + ui->splitter->setSizes({1,1}); + } + compiler->updateCommandCpp(data.compileCommandCpp); compiler->updateCommandJava(data.compileCommandJava); runner->updateCompileCommandCpp(data.compileCommandCpp); diff --git a/src/preferencewindow.cpp b/src/preferencewindow.cpp index 6ec616d0c..047e27e83 100644 --- a/src/preferencewindow.cpp +++ b/src/preferencewindow.cpp @@ -79,6 +79,7 @@ void PreferenceWindow::applySettingsToui() ui->format_hotkey->setKeySequence(manager->getHotkeyFormat()); ui->compileRun_hotkey->setKeySequence(manager->getHotkeyCompileRun()); ui->kill_hotkey->setKeySequence(manager->getHotkeyKill()); + ui->toggle_hotkey->setKeySequence(manager->getHotkeyViewModeToggler()); } void PreferenceWindow::extractSettingsFromUi() @@ -124,6 +125,7 @@ void PreferenceWindow::extractSettingsFromUi() manager->setHotkeyFormat(ui->format_hotkey->keySequence()); manager->setHotkeyCompile(ui->compile_hotkey->keySequence()); manager->setHotkeyCompileRun(ui->compileRun_hotkey->keySequence()); + manager->setHotkeyViewModeToggler(ui->toggle_hotkey->keySequence()); } void PreferenceWindow::resetSettings() @@ -173,6 +175,7 @@ void PreferenceWindow::resetSettings() manager->setHotkeyCompile(QKeySequence()); manager->setHotkeyCompileRun(QKeySequence()); manager->setHotkeyFormat(QKeySequence()); + manager->setHotkeyViewModeToggler(QKeySequence()); } void PreferenceWindow::updateShow() @@ -205,6 +208,7 @@ void PreferenceWindow::on_hotkeys_clicked(bool checked) ui->run_hotkey->setEnabled(checked); ui->kill_hotkey->setEnabled(checked); ui->format_hotkey->setEnabled(checked); + ui->toggle_hotkey->setEnabled(checked); } void PreferenceWindow::on_font_button_clicked() diff --git a/ui/appwindow.ui b/ui/appwindow.ui index 69d800c19..3f2a92ae5 100644 --- a/ui/appwindow.ui +++ b/ui/appwindow.ui @@ -58,7 +58,7 @@ 0 0 800 - 26 + 22 @@ -100,7 +100,16 @@ + + + View + + + + + + @@ -252,6 +261,30 @@ Support me + + + true + + + Editor Mode + + + + + true + + + IO Mode + + + + + true + + + Split Mode + + diff --git a/ui/preferencewindow.ui b/ui/preferencewindow.ui index f559963fd..317194d19 100644 --- a/ui/preferencewindow.ui +++ b/ui/preferencewindow.ui @@ -32,7 +32,7 @@ QTabWidget::Rounded - 2 + 3 @@ -530,8 +530,8 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:9.6pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2';">You must </span><a href="https://github.com/jmerle/competitive-companion"><span style=" font-family:'MS Shell Dlg 2'; text-decoration: underline; color:#0000ff;">download</span></a><span style=" font-family:'MS Shell Dlg 2';"> the Browser extension that parses and sends the testcases to the editor on the port specified above. You may need to change the port from Browser extension setting to match above value. </span><span style=" font-family:'MS Shell Dlg 2'; font-weight:600;">Restart is required, if you change the port</span><span style=" font-family:'MS Shell Dlg 2';">. Competitive Companion is a separate project by other developer and any issue or feature requests you want in browser extension should be done on above URL.</span></p></body></html> +</style></head><body style=" font-family:'Inter'; font-size:10pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:9.6pt;">You must </span><a href="https://github.com/jmerle/competitive-companion"><span style=" font-family:'MS Shell Dlg 2'; font-size:9.6pt; text-decoration: underline; color:#0000ff;">download</span></a><span style=" font-family:'MS Shell Dlg 2'; font-size:9.6pt;"> the Browser extension that parses and sends the testcases to the editor on the port specified above. You may need to change the port from Browser extension setting to match above value. </span><span style=" font-family:'MS Shell Dlg 2'; font-size:9.6pt; font-weight:600;">Restart is required, if you change the port</span><span style=" font-family:'MS Shell Dlg 2'; font-size:9.6pt;">. Competitive Companion is a separate project by other developer and any issue or feature requests you want in browser extension should be done on above URL.</span></p></body></html> @@ -657,6 +657,16 @@ p, li { white-space: pre-wrap; } + + + + Hotkey for Toggling View Mode + + + + + + @@ -672,8 +682,8 @@ p, li { white-space: pre-wrap; } <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:9.6pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2';">Please do not type any standard shortcuts like </span><span style=" font-family:'Courier New';">CTRL+R, CTRL+Shift+R, CTRL+C</span><span style=" font-family:'MS Shell Dlg 2';"> etc that are already in use by the editor. It will cause disambiguity and no shortcuts will work.</span></p></body></html> +</style></head><body style=" font-family:'Inter'; font-size:10pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:9.6pt;">Please do not type any standard shortcuts like </span><span style=" font-family:'Courier New'; font-size:9.6pt;">CTRL+R, CTRL+Shift+R, CTRL+C</span><span style=" font-family:'MS Shell Dlg 2'; font-size:9.6pt;"> etc that are already in use by the editor. It will cause disambiguity and no shortcuts will work.</span></p></body></html> @@ -800,8 +810,8 @@ p, li { white-space: pre-wrap; } <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:9.6pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2';">The file you choose here will be made available to you in the code editor. Every new Tab will be populated with contents from files of default language. If you change language from a tab to other (non-default) language and your files are saved, the editor will load corresponding templates.</span></p></body></html> +</style></head><body style=" font-family:'Inter'; font-size:10pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:9.6pt;">The file you choose here will be made available to you in the code editor. Every new Tab will be populated with contents from files of default language. If you change language from a tab to other (non-default) language and your files are saved, the editor will load corresponding templates.</span></p></body></html>