Skip to content

Commit

Permalink
feat: custom background color in sticky mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ChungZH committed Jun 7, 2020
1 parent f4f3820 commit b24b59b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

# Some files
.DS_Store
*.pro.user
*.autosave
*.user
.vs/
*.qm
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
- Hide statusbar
- Use general font (not monospace)
- Smaller window
- Custom background color

### 🐞 Bug fix

Expand Down
14 changes: 11 additions & 3 deletions src/core/texteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ void TextEditor::open()

QPlainTextEdit::clear();

const auto def = m_repository.definitionForFileName(fileName);
auto def = m_repository.definitionForFileName(fileName);
if (currentMode == 1) def = m_repository.definitionForName("Markdown");
m_highlighter->setDefinition(def);

QTextStream in(&file);
Expand Down Expand Up @@ -354,9 +355,10 @@ void TextEditor::setTheme(const KSyntaxHighlighting::Theme &theme)
}
void TextEditor::setEditorFont(const QFont &font)
{
QPlainTextEdit::setFont(
QFont(font.family(), configManager->getEditorFontSize()));
QFont f = QFont(font.family(), configManager->getEditorFontSize());
QPlainTextEdit::setFont(f);
configManager->setEditorFontFamily(font.family());
lineNumberArea->setFont(f);
}

void TextEditor::setEditorFontSize(const int &size)
Expand Down Expand Up @@ -388,12 +390,18 @@ void TextEditor::switchMode(const int &mode)
currentMode = mode;
QPlainTextEdit::setFont(QFont(configManager->getEditorFontFamily(),
configManager->getEditorFontSize()));
setStyleSheet("background: " +
QString::number(m_highlighter->theme().editorColor(
KSyntaxHighlighting::Theme::BackgroundColor)));
setEditorFont(configManager->getEditorFontFamily());
} else if (mode == 1) {
lineNumberArea->hide();
setViewportMargins(0, 0, 0, 0);
currentMode = mode;
setFont(
QFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont).toString(),
configManager->getEditorFontSize()));
auto def = m_repository.definitionForName("Markdown");
m_highlighter->setDefinition(def);
}
}
63 changes: 42 additions & 21 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,34 @@ MainWindow::MainWindow(ConfigManager *cfManager, QWidget *parent)
setBaseSize(size());
ToolBar = new QToolBar;

currentBGColor = QColor("#537EFF");
// Sticky note mode

SToolBar = new QToolBar;
changeBgColor = new QAction;
changeBgColor->setToolTip(tr("Change background color"));
changeBgColor->setIconText("BG Color");
currentColor = "#AAFFFF";

SToolBar->addAction(changeBgColor);
SToolBar->addAction(ui->actionNormalmode);

this->addToolBar(Qt::ToolBarArea::BottomToolBarArea, SToolBar);
SToolBar->setVisible(0);

ColorDialog = new QColorDialog;

connect(changeBgColor, &QAction::triggered, [&]() { ColorDialog->open(); });
connect(ColorDialog, &QColorDialog::currentColorChanged,
[&](const QColor &color) {
currentColor = color;
plainTextEdit->setStyleSheet("background-color: " +
currentColor.name());
});

//

this->addToolBar(Qt::LeftToolBarArea, ToolBar);

normalMode(1);

plainTextEdit = new TextEditor(configManager);
Expand Down Expand Up @@ -201,17 +226,20 @@ void MainWindow::normalMode(bool first)
if (!first) {
resize(baseSize());
plainTextEdit->switchMode(0);
ToolBar->setVisible(1);
SToolBar->setVisible(0);
} else {
ToolBar->addAction(ui->actionNew);
ToolBar->addAction(ui->actionOpen);
ToolBar->addAction(ui->actionSave);
ToolBar->addAction(ui->actionSave_As);
ToolBar->addAction(ui->actionPreferences);
ToolBar->addAction(ui->actionUndo);
ToolBar->addAction(ui->actionRedo);
ToolBar->addAction(ui->actionQuit);
ToolBar->addAction(ui->actionAbout);
ToolBar->addAction(ui->actionSticky_note_mode);
}
ToolBar->addAction(ui->actionNew);
ToolBar->addAction(ui->actionOpen);
ToolBar->addAction(ui->actionSave);
ToolBar->addAction(ui->actionSave_As);
ToolBar->addAction(ui->actionPreferences);
ToolBar->addAction(ui->actionUndo);
ToolBar->addAction(ui->actionRedo);
ToolBar->addAction(ui->actionQuit);
ToolBar->addAction(ui->actionAbout);
ToolBar->addAction(ui->actionSticky_note_mode);
ui->actionPreferences->setEnabled(1);
currentMode = 0;
}
Expand All @@ -224,19 +252,12 @@ void MainWindow::stickyNoteMode()
{
resize(baseSize() * 0.7);
plainTextEdit->switchMode(1);
plainTextEdit->setStyleSheet("background: " + currentColor.name());
statusBar()->clearMessage();
ui->actionPreferences->setDisabled(1);

ToolBar->removeAction(ui->actionNew);
ToolBar->removeAction(ui->actionOpen);
ToolBar->removeAction(ui->actionSave);
ToolBar->removeAction(ui->actionSave_As);
ToolBar->removeAction(ui->actionPreferences);
ToolBar->removeAction(ui->actionUndo);
ToolBar->removeAction(ui->actionRedo);
ToolBar->removeAction(ui->actionQuit);
ToolBar->removeAction(ui->actionAbout);
ToolBar->removeAction(ui->actionSticky_note_mode);
ToolBar->setVisible(0);
SToolBar->setVisible(1);

currentMode = 1;
}
Expand Down
14 changes: 11 additions & 3 deletions src/ui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QAction>
#include <QColorDialog>
#include <QMainWindow>
#include <QPlainTextEdit>
#include <QToolBar>
Expand Down Expand Up @@ -53,14 +55,20 @@ class MainWindow : public QMainWindow
QToolBar *ToolBar;
ConfigManager *configManager;
PreferencesWindow *pfWindow;
QWidget *stickyBGColorSelector;
QColor currentBGColor; // only in sticky mode

/**
* @brief currentMode
* 0: normal mode
* 1: sticky mode
*/
int currentMode;

// Sticky note mode

QToolBar *SToolBar;
QAction *changeBgColor;
QColorDialog *ColorDialog;
QColor currentColor;

//
};
#endif // MAINWINDOW_H

0 comments on commit b24b59b

Please sign in to comment.