Skip to content

Commit

Permalink
WIP: Add View Modes and Toggle shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
coder3101 committed Jan 8, 2020
1 parent f32cd54 commit 5bfc33c
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 10 deletions.
15 changes: 15 additions & 0 deletions include/SettingsManager.hpp
Expand Up @@ -29,6 +29,12 @@
namespace Settings
{

enum ViewMode{
FULL_EDITOR,
FULL_IO,
SPLIT
};

struct SettingsData
{
int companionPort;
Expand Down Expand Up @@ -74,6 +80,9 @@ struct SettingsData
QKeySequence hotkeyCompileRun;
QKeySequence hotkeyFormat;
QKeySequence hotkeyKill;
QKeySequence hotkeyViewModeToggler;

ViewMode viewMode;
};

class SettingManager
Expand Down Expand Up @@ -162,6 +171,9 @@ class SettingManager
bool isCheckUpdateOnStartup();
void checkUpdateOnStartup(bool value);

ViewMode getViewMode();
void setViewMode(ViewMode v);

SettingsData toData();
~SettingManager();

Expand All @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion include/appwindow.hpp
Expand Up @@ -58,6 +58,7 @@ class AppWindow : public QMainWindow
void onSettingsApplied();
void onSplitterMoved(int, int);
void onIncomingCompanionRequest(Network::CompanionData);
void onViewModeToggle();

void on_actionCompile_triggered();

Expand All @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions src/SettingsManager.cpp
Expand Up @@ -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());
Expand All @@ -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();
Expand Down Expand Up @@ -406,6 +431,8 @@ SettingsData SettingManager::toData()
data.hotkeyCompileRun = getHotkeyCompileRun();
data.hotkeyKill = getHotkeyKill();
data.hotkeyFormat = getHotkeyFormat();
data.hotkeyViewModeToggler = getHotkeyViewModeToggler();
data.viewMode = getViewMode();

return data;
}
Expand Down
66 changes: 66 additions & 0 deletions src/appwindow.cpp
Expand Up @@ -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();

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -489,3 +528,30 @@ void AppWindow::on_actionKill_Processes_triggered()
auto tmp = dynamic_cast<MainWindow *>(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());
}
17 changes: 16 additions & 1 deletion src/mainwindow.cc
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/preferencewindow.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -173,6 +175,7 @@ void PreferenceWindow::resetSettings()
manager->setHotkeyCompile(QKeySequence());
manager->setHotkeyCompileRun(QKeySequence());
manager->setHotkeyFormat(QKeySequence());
manager->setHotkeyViewModeToggler(QKeySequence());
}

void PreferenceWindow::updateShow()
Expand Down Expand Up @@ -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()
Expand Down
35 changes: 34 additions & 1 deletion ui/appwindow.ui
Expand Up @@ -58,7 +58,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>26</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down Expand Up @@ -100,7 +100,16 @@
<addaction name="actionCheck_for_updates"/>
<addaction name="actionSupport_me"/>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
<string>View</string>
</property>
<addaction name="actionEditor_Mode"/>
<addaction name="actionIO_Mode"/>
<addaction name="actionSplit_Mode"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuView"/>
<addaction name="menuEditor"/>
<addaction name="menuActions"/>
<addaction name="menuSettings"/>
Expand Down Expand Up @@ -252,6 +261,30 @@
<string>Support me</string>
</property>
</action>
<action name="actionEditor_Mode">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Editor Mode</string>
</property>
</action>
<action name="actionIO_Mode">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>IO Mode</string>
</property>
</action>
<action name="actionSplit_Mode">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Split Mode</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down
24 changes: 17 additions & 7 deletions ui/preferencewindow.ui
Expand Up @@ -32,7 +32,7 @@
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>2</number>
<number>3</number>
</property>
<widget class="QWidget" name="editor">
<attribute name="title">
Expand Down Expand Up @@ -530,8 +530,8 @@
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:9.6pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2';&quot;&gt;You must &lt;/span&gt;&lt;a href=&quot;https://github.com/jmerle/competitive-companion&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; text-decoration: underline; color:#0000ff;&quot;&gt;download&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2';&quot;&gt; 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. &lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-weight:600;&quot;&gt;Restart is required, if you change the port&lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2';&quot;&gt;. 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.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Inter'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9.6pt;&quot;&gt;You must &lt;/span&gt;&lt;a href=&quot;https://github.com/jmerle/competitive-companion&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9.6pt; text-decoration: underline; color:#0000ff;&quot;&gt;download&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9.6pt;&quot;&gt; 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. &lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9.6pt; font-weight:600;&quot;&gt;Restart is required, if you change the port&lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9.6pt;&quot;&gt;. 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.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -657,6 +657,16 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_44">
<property name="text">
<string>Hotkey for Toggling View Mode</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QKeySequenceEdit" name="toggle_hotkey"/>
</item>
</layout>
</item>
<item row="4" column="0">
Expand All @@ -672,8 +682,8 @@ p, li { white-space: pre-wrap; }
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:9.6pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2';&quot;&gt;Please do not type any standard shortcuts like &lt;/span&gt;&lt;span style=&quot; font-family:'Courier New';&quot;&gt;CTRL+R, CTRL+Shift+R, CTRL+C&lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2';&quot;&gt; etc that are already in use by the editor. It will cause disambiguity and no shortcuts will work.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Inter'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9.6pt;&quot;&gt;Please do not type any standard shortcuts like &lt;/span&gt;&lt;span style=&quot; font-family:'Courier New'; font-size:9.6pt;&quot;&gt;CTRL+R, CTRL+Shift+R, CTRL+C&lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9.6pt;&quot;&gt; etc that are already in use by the editor. It will cause disambiguity and no shortcuts will work.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -800,8 +810,8 @@ p, li { white-space: pre-wrap; }
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:9.6pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2';&quot;&gt;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.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Inter'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9.6pt;&quot;&gt;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.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 5bfc33c

Please sign in to comment.