From: hama Date: Thu, 20 Aug 2015 22:21:50 +0000 (+0200) Subject: Storage settings X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=21bcab4220de1ff82226f2f840ce174fdba830f4;p=reqt Storage settings --- diff --git a/appl/reditor/main.cpp b/appl/reditor/main.cpp index a145881..e11e665 100644 --- a/appl/reditor/main.cpp +++ b/appl/reditor/main.cpp @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) { ReDebugAppender appender; appender.setAutoDelete(false); logger.addAppender(&appender); - MainWindow w(workspace, project); + MainWindow w(workspace, project, &logger); logger.log(LOG_INFO, 1, "start"); w.show(); diff --git a/appl/reditor/mainwindow.cpp b/appl/reditor/mainwindow.cpp index 9c6e099..9a84764 100644 --- a/appl/reditor/mainwindow.cpp +++ b/appl/reditor/mainwindow.cpp @@ -14,18 +14,20 @@ #include MainWindow::MainWindow(const char* workspace, const char* project, - QWidget *parent) : + ReLogger* logger, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), + m_project(NULL), m_workspace(NULL), - m_project(NULL) { + m_logger(logger) { if (workspace == NULL) workspace = QDir::homePath().toUtf8(); changeWorkspace(workspace == NULL ? QDir::homePath() : workspace); QString proj(project == NULL ? "" : project); if (project == NULL) { - QStringList lastProjects = m_workspace->historyAsList("projects"); + QStringList lastProjects; + m_workspace->historyAsList("projects", lastProjects); int ix = 0; while (proj.isEmpty() && ix < lastProjects.size()) { QFileInfo dir(lastProjects.at(ix)); @@ -33,7 +35,7 @@ MainWindow::MainWindow(const char* workspace, const char* project, proj = lastProjects.at(ix); } if (!proj.isEmpty()) - m_project = new Project(proj); + changeProject(proj); } ui->setupUi(this); @@ -60,7 +62,9 @@ MainWindow::~MainWindow() { */ void MainWindow::changeProject(const QString& path) { delete m_project; - m_project = new Project(path); + m_project = new Project(path, m_logger); + int maxEntries = m_workspace->intValue("history.max_projects"); + m_workspace->addHistoryEntry("projects", path, ';', maxEntries); } /** @@ -70,7 +74,7 @@ void MainWindow::changeProject(const QString& path) { */ void MainWindow::changeWorkspace(const QString& path) { delete m_workspace; - m_workspace = new Workspace(path); + m_workspace = new Workspace(path, m_logger); } /** @@ -82,23 +86,16 @@ void MainWindow::openFile(const QString& name) { ReEdit* edit = ui->widget; edit->setLines(m_file); edit->setCursorLine(0); + int maxEntries = m_workspace->intValue("history.max_files"); + m_workspace->addHistoryEntry("files", name, ';', maxEntries); } /** * Closes the current project. */ void MainWindow::closeProject() { - if (!m_project.isEmpty()) { - - } -} - -/** - * Opens a project. - */ -void MainWindow::openProject(const QString& name) { - closeProject(); - m_project = name; + delete m_project; + m_project = NULL; } /** @@ -108,6 +105,9 @@ void MainWindow::open() { ProjectSelection dialog(this); dialog.exec(); } +ReLogger* MainWindow::logger() const { + return m_logger; +} /** * Returns the current workspace. diff --git a/appl/reditor/mainwindow.hpp b/appl/reditor/mainwindow.hpp index a80d532..bb5757c 100644 --- a/appl/reditor/mainwindow.hpp +++ b/appl/reditor/mainwindow.hpp @@ -14,7 +14,7 @@ #include #ifndef REBASE_HPP -#include "base/rebase.hpp" +#include "reditor.hpp" #endif namespace Ui { class MainWindow; @@ -25,15 +25,15 @@ class MainWindow: public QMainWindow { public: explicit MainWindow(const char* workspace, const char* project, - QWidget *parent = 0); + ReLogger* logger, QWidget *parent = 0); ~MainWindow(); void changeProject(const QString& path); void changeWorkspace(const QString& path); void closeProject(); void openFile(const QString& name); - void openProject(const QString& name); Storage* project() const; Storage* workspace() const; + ReLogger* logger() const; public slots: void open(); @@ -42,6 +42,7 @@ private: ReFile* m_file; Storage* m_project; Storage* m_workspace; + ReLogger* m_logger; }; #endif // MAINWINDOW_HPP diff --git a/appl/reditor/project.cpp b/appl/reditor/project.cpp index b64f6d0..314cb1f 100644 --- a/appl/reditor/project.cpp +++ b/appl/reditor/project.cpp @@ -1,14 +1,23 @@ /* - * Licence: + * project.cpp + * + * License: Public Domain * You can use and modify this file without any restriction. - * There is no warranty. - * You also can use the licence from http://www.wtfpl.net/. - * The original sources can be found on https://github.com/republib. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib */ #include "reditor.hpp" -Project::Project(const QString& path) : - Storage(path, "proj") { +/** + * Constructor. + * + * @param path the directory containing the configuration + * @param logger the logger + */ +Project::Project(const QString& path, ReLogger* logger) : + Storage(path, "proj", logger) { } diff --git a/appl/reditor/project.hpp b/appl/reditor/project.hpp index 7768602..e088f47 100644 --- a/appl/reditor/project.hpp +++ b/appl/reditor/project.hpp @@ -1,9 +1,12 @@ /* - * Licence: + * project.hpp + * + * License: Public Domain * You can use and modify this file without any restriction. - * There is no warranty. - * You also can use the licence from http://www.wtfpl.net/. - * The original sources can be found on https://github.com/republib. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib */ #ifndef PROJECT_HPP @@ -11,7 +14,7 @@ class Project: public Storage { public: - Project(const QString& path); + Project(const QString& path, ReLogger* logger); }; #endif // PROJECT_HPP diff --git a/appl/reditor/projectselection.cpp b/appl/reditor/projectselection.cpp index 8ccc1dc..8550f56 100644 --- a/appl/reditor/projectselection.cpp +++ b/appl/reditor/projectselection.cpp @@ -1,9 +1,12 @@ /* - * Licence: + * projectselection.cpp + * + * License: Public Domain * You can use and modify this file without any restriction. - * There is no warranty. - * You also can use the licence from http://www.wtfpl.net/. - * The original sources can be found on https://github.com/republib. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib */ #include "reditor.hpp" @@ -63,7 +66,7 @@ void ProjectSelection::open() { error("does not exists: " + name); else { if (file.isDir()) - m_mainWindow->openProject(name); + m_mainWindow->changeProject(name); else m_mainWindow->openFile(name); close(); @@ -89,8 +92,8 @@ void ProjectSelection::openLastProject() { */ void ProjectSelection::selectDir() { QString name = ui->lineEditOpen->text(); - if (name.isEmpty()) - name = m_mainWindow->project(); + if (name.isEmpty() && m_mainWindow->project() != NULL) + name = m_mainWindow->project()->path(); name = QFileDialog::getExistingDirectory(this, tr("Select Project Directory"), name); if (!name.isEmpty()) { diff --git a/appl/reditor/projectselection.hpp b/appl/reditor/projectselection.hpp index 0439acc..0c4913b 100644 --- a/appl/reditor/projectselection.hpp +++ b/appl/reditor/projectselection.hpp @@ -1,9 +1,12 @@ /* - * Licence: + * projectselection.hpp + * + * License: Public Domain * You can use and modify this file without any restriction. - * There is no warranty. - * You also can use the licence from http://www.wtfpl.net/. - * The original sources can be found on https://github.com/republib. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib */ #ifndef PROJECTSELECTION_HPP diff --git a/appl/reditor/reditor.hpp b/appl/reditor/reditor.hpp index 47c5712..4d083d1 100644 --- a/appl/reditor/reditor.hpp +++ b/appl/reditor/reditor.hpp @@ -1,9 +1,12 @@ /* - * Licence: + * reditor.hpp + * + * License: Public Domain * You can use and modify this file without any restriction. - * There is no warranty. - * You also can use the licence from http://www.wtfpl.net/. - * The original sources can be found on https://github.com/republib. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib */ #ifndef REDITOR_HPP diff --git a/appl/reditor/storage.cpp b/appl/reditor/storage.cpp index 0acd8d9..f13c302 100644 --- a/appl/reditor/storage.cpp +++ b/appl/reditor/storage.cpp @@ -1,31 +1,160 @@ /* - * Licence: + * storage.cpp + * + * License: Public Domain * You can use and modify this file without any restriction. - * There is no warranty. - * You also can use the licence from http://www.wtfpl.net/. - * The original sources can be found on https://github.com/republib. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib */ #include "reditor.hpp" +enum { + LOC_BOOL_VALUE_1 = LOC_FIRST_OF(LOC_STORAGE), // 11701 + LOC_BOOL_VALUE_2, // 11702 + LOC_INT_VALUE_1, // 11703 + LOC_INT_VALUE_2, // 11704 + LOC_STRING_VALUE_1, // 11705 + LOC_STRING_VALUE_2, // 11706 +}; + /** * Constructor. * * @param path the parent directory for the storage files * @param prefix type of the storage: "proj" or "ws" (workspace) */ -Storage::Storage(const QString& path, const QString prefix) : +Storage::Storage(const QString& path, const QString prefix, ReLogger* logger) : m_path(path), - m_history(path + OS_SEPARATOR + ".reditor." + prefix + ".history"), - m_settings(path + OS_SEPARATOR + ".reditor." + prefix + ".settings") { + m_fileHistory(path + OS_SEPARATOR + ".reditor." + prefix + ".history"), + m_fileSettings( + path + OS_SEPARATOR + ".reditor." + prefix + ".settings"), + m_settings(), + m_chapters(), + m_logger(logger) { } +/* + * Adds an entry to a history item at the first position. + * + * The entry will removed from the other positions. + * + * @param key the key in the map + * @param value the value to add + * @param separator separates the entries in the history item + * @param maxEntries the maximal count of entries in the history item.
+ * If the number exceeds the last entries will be removed + * @param form the prefix of the key. If NULL the current form will be taken + */ void Storage::addHistoryEntry(const char* key, const QString& value, char separator, int maxEntries) { - ReStateStorage store(m_history); + ReStateStorage store(m_fileHistory); store.addHistoryEntry(key, value, separator, maxEntries); store.close(); store.flushMap(); } +/** + * Returns the value of a boolean property. + * + * @param name the name of the property + * @return the value of the property + */ +bool Storage::boolValue(const char* name) { + bool rc = false; + Property* property = m_settings.value(name, NULL); + if (property == NULL) + m_logger->logv(LOG_ERROR, LOC_BOOL_VALUE_1, "missing bool property %s", + name); + else if (property->m_type != PT_BOOL) + m_logger->logv(LOG_ERROR, LOC_BOOL_VALUE_2, "not a bool property %s", + name); + else + rc = !property->m_value.isEmpty(); + return rc; +} +/** + * Returns a history item as a list. + * + * @param key key of the history item + * @param list OUT: the list is filled with the history entries + * @param form a common prefix of the key. If NULL the current form is used + * @return list (for chaining) + */ +QStringList&Storage::historyAsList(const char* key, QStringList& list, + const char* form) { + ReStateStorage store(m_fileHistory); + QStringList& rc = store.historyAsList(key, list, form); + store.close(); + return rc; +} + +/** + * Returns the value of an integer property. + * + * @param name the name of the property + * @return the value of the property + */ +int Storage::intValue(const char* name) { + int rc = 0; + Property* property = m_settings.value(name, NULL); + if (property == NULL) + m_logger->logv(LOG_ERROR, LOC_INT_VALUE_1, "missing int property %s", + name); + else if (property->m_type != PT_INT) + m_logger->logv(LOG_ERROR, LOC_INT_VALUE_2, "not a int property %s", + name); + else + rc = property->m_value.toInt(); + return rc; +} + +/** + * Returns the directory containing the configuration data. + * + * @return the name of the storage's directory + */ +QString Storage::path() const { + return m_path; +} + +/** + * Returns the value of a string property. + * + * @param name the name of the property + * @return the value of the property + */ +QString Storage::stringValue(const char* name) { + QString rc = ""; + Property* property = m_settings.value(name, NULL); + if (property == NULL) + m_logger->logv(LOG_ERROR, LOC_STRING_VALUE_1, + "missing string property %s", name); + else if (property->m_type != PT_STRING) + m_logger->logv(LOG_ERROR, LOC_STRING_VALUE_2, + "not a string property %s", name); + else + rc = property->m_value; + return rc; +} + +/** + * Inserts a property. + * + * @param property the property to insert + */ +void Storage::insertProperty(Property* property) { + m_settings.insert(property->m_name, property); + QByteArray chapter(property->m_name); + int ix = chapter.lastIndexOf('.'); + chapter = chapter.left(ix); + QList* list = m_chapters.value(chapter, NULL); + if (list == NULL) { + m_chapters.insert(chapter, list = new QList()); + } + list->append(property); +} + diff --git a/appl/reditor/storage.hpp b/appl/reditor/storage.hpp index 9147586..84f7c7b 100644 --- a/appl/reditor/storage.hpp +++ b/appl/reditor/storage.hpp @@ -1,24 +1,69 @@ /* - * Licence: + * storage.hpp + * + * License: Public Domain * You can use and modify this file without any restriction. - * There is no warranty. - * You also can use the licence from http://www.wtfpl.net/. - * The original sources can be found on https://github.com/republib. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib */ #ifndef STORAGE_HPP #define STORAGE_HPP +enum PropertyType { + PT_UNDEF, + PT_INT, + PT_STRING, + PT_BOOL +}; + +class Property { +public: + Property(const char* name, const QString& title, const QString& description, + const QString& defaultValue, PropertyType type, const char* limits = + NULL) : + m_name(name), + m_title(title), + m_description(description), + m_value(defaultValue), + m_defaultValue(defaultValue), + m_type(type), + m_limits(limits) { + } + +public: + const char* m_name; + QString m_title; + QString m_description; + QString m_value; + QString m_defaultValue; + PropertyType m_type; + const char* m_limits; +}; + class Storage { public: - Storage(const QString& path, const QString prefix); + Storage(const QString& path, const QString prefix, ReLogger* logger); public: void addHistoryEntry(const char* key, const QString& value, char separator, int maxEntries); + bool boolValue(const char* name); + QStringList& historyAsList(const char* key, QStringList& list, + const char* form = NULL); + int intValue(const char* name); + QString path() const; + QString stringValue(const char* name); +protected: + void insertProperty(Property* property); protected: QString m_path; - QString m_history; - QString m_settings; + QString m_fileHistory; + QString m_fileSettings; + QMap m_settings; + QMap*> m_chapters; + ReLogger* m_logger; }; #endif // STORAGE_HPP diff --git a/appl/reditor/workspace.cpp b/appl/reditor/workspace.cpp index 5f92d61..64d54a3 100644 --- a/appl/reditor/workspace.cpp +++ b/appl/reditor/workspace.cpp @@ -1,15 +1,37 @@ /* - * Licence: + * workspace.cpp + * + * License: Public Domain * You can use and modify this file without any restriction. - * There is no warranty. - * You also can use the licence from http://www.wtfpl.net/. - * The original sources can be found on https://github.com/republib. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib */ #include "reditor.hpp" -Workspace::Workspace(const QString& path) : - Storage(path, "ws") { - +/** + * Constructor. + * + * @param path the directory containing the configuration + * @param logger the logger + */ +Workspace::Workspace(const QString& path, ReLogger* logger) : + Storage(path, "ws", logger) { + insertProperty( + new Property("editor.tabwidth", QObject::tr("Tabulator width"), + QObject::tr("Maximal length of the gap displaying a tabulator"), + "4", PT_INT, "[1,16]")); + insertProperty( + new Property("history.max_projects", + QObject::tr("Maximal project entries"), + QObject::tr( + "Maximal number of projects in the 'last opened projects'"), + "20", PT_INT, "[1,100]")); + insertProperty( + new Property("history.max_files", QObject::tr("Maximal file entries"), + QObject::tr("Maximal number of files in the 'last opened files'"), + "20", PT_INT, "[1,100]")); } diff --git a/appl/reditor/workspace.hpp b/appl/reditor/workspace.hpp index 4602619..4be110b 100644 --- a/appl/reditor/workspace.hpp +++ b/appl/reditor/workspace.hpp @@ -1,9 +1,12 @@ /* - * Licence: + * workspace.hpp + * + * License: Public Domain * You can use and modify this file without any restriction. - * There is no warranty. - * You also can use the licence from http://www.wtfpl.net/. - * The original sources can be found on https://github.com/republib. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib */ #ifndef WORKSPACE_HPP @@ -11,7 +14,7 @@ class Workspace: public Storage { public: - Workspace(const QString& path); + Workspace(const QString& path, ReLogger* logger); }; #endif // WORKSPACE_HPP diff --git a/base/ReFile.cpp b/base/ReFile.cpp index 57efc9a..31abc84 100644 --- a/base/ReFile.cpp +++ b/base/ReFile.cpp @@ -142,9 +142,9 @@ void ReLines::insertPart(int lineNo, int col, const QString& text, if (col == 0) replace(lineNo, text + current); else if (col < current.length()) - replace(lineNo, current.mid(0, col) + text + current.mid(col)); + replace(lineNo, current.left(col) + text + current.mid(col)); else - replace(lineNo, current.mid(0, col) + text); + replace(lineNo, current.left(col) + text); } } @@ -168,9 +168,9 @@ void ReLines::insertText(int lineNo, int col, const QString& text) { splitLine(lineNo, col, true); int newLines = 0; if (lineNo < length()) - insertPart(lineNo, col, text.mid(0, endOfLine), true); + insertPart(lineNo, col, text.left(endOfLine), true); else - insertLines(lineNo, text.mid(0, endOfLine), true); + insertLines(lineNo, text.left(endOfLine), true); int lastEoLn = text.lastIndexOf('\n'); if (lastEoLn != endOfLine) { int oldCount = lineCount(); @@ -240,9 +240,9 @@ bool ReLines::removePart(int lineNo, int col, int count, bool withUndo) { if (col == 0) replace(lineNo, current.mid(count)); else if (col + count >= length) - replace(lineNo, current.mid(0, col)); + replace(lineNo, current.left(col)); else - replace(lineNo, current.mid(0, col) + current.mid(col + count)); + replace(lineNo, current.left(col) + current.mid(col + count)); } } return rc; @@ -297,8 +297,8 @@ void ReLines::splitLine(int lineNo, int col, bool withUndo) { append(current.mid(col)); else insert(lineNo + 1, current.mid(col)); - x = current.mid(0, col); - replace(lineNo, current.mid(0, col)); + x = current.left(col); + replace(lineNo, current.left(col)); } } } diff --git a/base/ReQStringUtil.cpp b/base/ReQStringUtil.cpp index 5773e1b..0b5b7c9 100644 --- a/base/ReQStringUtil.cpp +++ b/base/ReQStringUtil.cpp @@ -31,7 +31,7 @@ ReString ReQStringUtil::chomp(const ReString& text) { while (last >= 0 && (text[last] == '\n' || text[last] == '\r')) { last--; } - return last == text.length() - 1 ? text : text.mid(0, last + 1); + return last == text.length() - 1 ? text : text.left(last + 1); } /** diff --git a/cunit/cuReEdit.cpp b/cunit/cuReEdit.cpp index 6ab65ef..9fabc5e 100644 --- a/cunit/cuReEdit.cpp +++ b/cunit/cuReEdit.cpp @@ -1,9 +1,12 @@ /* - * Licence: + * cuReEdit.cpp + * + * License: Public Domain * You can use and modify this file without any restriction. - * There is no warranty. - * You also can use the licence from http://www.wtfpl.net/. - * The original sources can be found on https://github.com/republib. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib */ #include "base/rebase.hpp" #include "gui/regui.hpp" diff --git a/gui/ReEdit.cpp b/gui/ReEdit.cpp index b7dc779..a787dc0 100644 --- a/gui/ReEdit.cpp +++ b/gui/ReEdit.cpp @@ -36,11 +36,11 @@ inline int heightToFullHeight(int height) { * @param edit the parent */ ReLook::ReLook() : - m_font(NULL), - m_metrics(NULL), - m_foreground(FG_STANDARD), - m_background(BG_STANDARD), - m_edit(NULL) { + m_font(NULL), + m_metrics(NULL), + m_foreground(FG_STANDARD), + m_background(BG_STANDARD), + m_edit(NULL) { } /** @@ -50,8 +50,8 @@ ReLook::ReLook() : * @param look the presentation of the text */ ReEditText::ReEditText(const QString& text, ReLook* look) : - m_text(text), - m_look(look) { + m_text(text), + m_look(look) { } @@ -64,7 +64,7 @@ ReEditText::ReEditText(const QString& text, ReLook* look) : * @param edit the edit field (parent) */ void ReCursortLineBuilder::buildParagraph(ReParagraph& paragraph, int lineNo, - ReEdit* edit) { + ReEdit* edit) { if (lineNo == edit->cursorLineNo()) { for (int ix = 0; ix < paragraph.length(); ix++) { ReEditText* text = paragraph.at(ix); @@ -100,32 +100,32 @@ void ReCursortLineBuilder::buildParagraph(ReParagraph& paragraph, int lineNo, * @param parent NULL or a widget which destroy the instance */ ReEdit::ReEdit(QWidget* parent) : - QWidget(parent), - ReMouseCatcher(), - m_widthEdit(0), - m_heightEdit(0), - m_insertMode(true), - m_breakLines(false), - m_widthLineNumbers(50), - m_widthVScrollBar(16), - m_heightHScrollBar(16), - m_looks(), - m_standardBrush(new QBrush(Qt::SolidPattern)), - m_scrollbarBrush(new QBrush(Qt::SolidPattern)), - m_sliderBrush(new QBrush(Qt::ConicalGradientPattern)), - m_brushColors(), - m_standardPen(new QPen(Qt::SolidLine)), - m_standardFont(NULL), - m_standardMetrics(NULL), - m_fontColors(), - m_keyAlt(), - m_keyAltControl(), - m_keyAltControlShift(), - m_keyAltShift(), - m_keyControl(), - m_keyControlShift(), - m_keyRaw(), - m_keyShift() { + QWidget(parent), + ReMouseCatcher(), + m_widthEdit(0), + m_heightEdit(0), + m_insertMode(true), + m_breakLines(false), + m_widthLineNumbers(50), + m_widthVScrollBar(16), + m_heightHScrollBar(16), + m_looks(), + m_standardBrush(new QBrush(Qt::SolidPattern)), + m_scrollbarBrush(new QBrush(Qt::SolidPattern)), + m_sliderBrush(new QBrush(Qt::ConicalGradientPattern)), + m_brushColors(), + m_standardPen(new QPen(Qt::SolidLine)), + m_standardFont(NULL), + m_standardMetrics(NULL), + m_fontColors(), + m_keyAlt(), + m_keyAltControl(), + m_keyAltControlShift(), + m_keyAltShift(), + m_keyControl(), + m_keyControlShift(), + m_keyRaw(), + m_keyShift() { setFocusPolicy(Qt::WheelFocus); m_standardFont = new QFont("Courier"); m_standardFont->setStyleHint(QFont::TypeWriter); @@ -230,7 +230,7 @@ void ReEdit::assignKeysStandard() { * @param length OUT: the slider length in pixel */ void calcSliderSize(int size, int minSize, double sizeFactor, double posFactor, - int& position, int& length) { + int& position, int& length) { if (sizeFactor > 1.0) sizeFactor = 1.0; if (posFactor > 100) @@ -277,8 +277,8 @@ int ReEdit::cursorLineNo() const { * @param posHorizontal the position of the scrollbar as factor [0..1] */ void ReEdit::drawScrollbars(QPainter& painter, const QRect& rect, - double sizeVertical, double posVertical, double sizeHorizontal, - double posHorizontal) { + double sizeVertical, double posVertical, double sizeHorizontal, + double posHorizontal) { // We paint the vertical scrollbar: QBrush brush(*m_brushColors[ReLook::BG_SCROLLBAR], Qt::SolidPattern); painter.setBrush(brush); @@ -287,14 +287,14 @@ void ReEdit::drawScrollbars(QPainter& painter, const QRect& rect, static int width = 1; static int width2 = 2 * width; m_vScrollBar->setRect(x + width2, rect.top(), m_widthVScrollBar - width2, - rect.height() - m_heightHScrollBar - width); + rect.height() - m_heightHScrollBar - width); painter.drawRect(*m_vScrollBar); // We paint the horizontal scrollbar: m_hScrollBar->setRect(rect.left() + m_widthLineNumbers, - rect.bottom() - m_heightHScrollBar + width, - rect.width() - m_widthVScrollBar - m_widthLineNumbers, - m_heightHScrollBar - width2); + rect.bottom() - m_heightHScrollBar + width, + rect.width() - m_widthVScrollBar - m_widthLineNumbers, + m_heightHScrollBar - width2); painter.drawRect(*m_hScrollBar); // Slider (vertical) @@ -303,36 +303,36 @@ void ReEdit::drawScrollbars(QPainter& painter, const QRect& rect, int sliderSize = 0; int sliderPos = 0; calcSliderSize(rect.height() - m_heightHScrollBar, m_heightHScrollBar, - sizeVertical, posVertical, sliderPos, sliderSize); + sizeVertical, posVertical, sliderPos, sliderSize); m_vSlider->setRect(x + width2, rect.top() + sliderPos + width, - m_widthVScrollBar - width2, sliderSize - width2); + m_widthVScrollBar - width2, sliderSize - width2); painter.drawRect(*m_vSlider); int middle = m_vSlider->top() + m_vSlider->height() / 2; painter.drawLine(m_vSlider->left() + 2, middle, m_vSlider->right() - 2, - middle); + middle); middle -= m_heightHScrollBar / 2 - 2; painter.drawLine(m_vSlider->left() + 2, middle, m_vSlider->right() - 2, - middle); + middle); middle += m_heightHScrollBar - 4; painter.drawLine(m_vSlider->left() + 2, middle, m_vSlider->right() - 2, - middle); + middle); // Slider (horizontal) calcSliderSize(rect.width() - m_widthLineNumbers - m_widthVScrollBar, - m_heightHScrollBar, sizeHorizontal, posHorizontal, sliderPos, - sliderSize); + m_heightHScrollBar, sizeHorizontal, posHorizontal, sliderPos, + sliderSize); m_hSlider->setRect(rect.left() + m_widthLineNumbers + sliderPos, - rect.bottom() - m_heightHScrollBar + width, sliderSize - width, - m_heightHScrollBar - width2); + rect.bottom() - m_heightHScrollBar + width, sliderSize - width, + m_heightHScrollBar - width2); painter.drawRect(*m_hSlider); middle = m_hSlider->left() + m_hSlider->width() / 2; painter.drawLine(middle, m_hSlider->top() + 2, middle, - m_hSlider->bottom() - 2); + m_hSlider->bottom() - 2); middle -= m_heightHScrollBar / 2 - 2; painter.drawLine(middle, m_hSlider->top() + 2, middle, - m_hSlider->bottom() - 2); + m_hSlider->bottom() - 2); middle += m_heightHScrollBar - 4; painter.drawLine(middle, m_hSlider->top() + 2, middle, - m_hSlider->bottom() - 2); + m_hSlider->bottom() - 2); } /** @@ -420,7 +420,7 @@ void ReEdit::editorAction(ReEdit::EditorAction action) { m_cursorCol = m_lines->lineAt(m_cursorLineNo - 1).length() - 1; } if (m_lines->removePart(m_cursorLineNo, columnToIndex(currentCol), 1, - true)) + true)) m_cursorLineNo = max(0, m_cursorLineNo - 1); break; @@ -429,7 +429,7 @@ void ReEdit::editorAction(ReEdit::EditorAction action) { int lastIx = lastColOfCurrent(); if (m_cursorCol <= lastIx) { m_lines->removePart(m_cursorLineNo, m_cursorCol + 1, - lastIx - m_cursorCol, true); + lastIx - m_cursorCol, true); ensureCursorVisible(); } break; @@ -476,7 +476,7 @@ void ReEdit::editorAction(ReEdit::EditorAction action) { */ void ReEdit::ensureCursorVisible() { if (m_cursorLineNo < m_firstLine - || m_cursorLineNo >= m_firstLine + pageSize()) { + || m_cursorLineNo >= m_firstLine + pageSize()) { reposition(m_cursorLineNo, m_cursorCol); } if (m_cursorCol < 0) @@ -518,7 +518,7 @@ void ReEdit::keyPressEvent(QKeyEvent* event) { break; } } else if (shift && !keyText.isEmpty() && key != Qt::Key_Delete - && key != Qt::Key_Backspace) { + && key != Qt::Key_Backspace) { m_lines->insertText(m_cursorLineNo, m_cursorCol + 1, keyText); m_cursorCol++; } else { @@ -564,7 +564,7 @@ ReLines& ReEdit::lines() { * @return */ ReLook* ReEdit::lookOf(ReLook::ForeGround foreground, - ReLook::BackGround background) { + ReLook::BackGround background) { int index = foreground * ReLook::BG_COUNT + background; ReLook* rc = m_looks[index]; if (rc == NULL) { @@ -591,8 +591,8 @@ ReLook* ReEdit::lookOf(ReLook::ForeGround foreground, */ void ReEdit::mouseMoveEvent(QMouseEvent* event) { if (m_lastMousePosition.x() >= 0 - && (handleHScrollBar(event, true, this) - || handleVScrollBar(event, true, this))) { + && (handleHScrollBar(event, true, this) + || handleVScrollBar(event, true, this))) { emit repaint(); } } @@ -610,12 +610,12 @@ void ReEdit::mousePressEvent(QMouseEvent* event) { } else { QPoint position = event->pos(); m_cursorLineNo = position.y() - / heightToFullHeight(m_standardMetrics->height()) + m_firstLine; + / heightToFullHeight(m_standardMetrics->height()) + m_firstLine; int x = position.x(); int charWidth = m_standardMetrics->width('x'); x -= m_widthLineNumbers; if (x >= 0 - && x < m_widthEdit - m_widthLineNumbers - m_widthVScrollBar) { + && x < m_widthEdit - m_widthLineNumbers - m_widthVScrollBar) { if (x <= +charWidth / 2) m_cursorCol = m_firstCol - 1; else @@ -639,7 +639,7 @@ void ReEdit::mouseReleaseEvent(QMouseEvent* event) { m_lastMousePosition.setX(-1); m_lastMousePosition.setY(-1); } -inline static double fraction(int a, int b, double exception){ +inline static double fraction(int a, int b, double exception) { double rc = b == 0 ? exception : (double) a / b; return rc; } @@ -658,14 +658,14 @@ void ReEdit::paintEvent(QPaintEvent* event) { int pageSize = (rect.height() - m_heightHScrollBar) / lineHeight; int charWidth = m_standardMetrics->averageCharWidth(); int pageWidth = (rect.width() - m_widthVScrollBar - m_widthLineNumbers) - / charWidth; + / charWidth; int firstLine = m_firstLine; load(firstLine, pageSize, pageWidth, this); QPainter painter(this); ReLook* look = lookOf(ReLook::FG_STANDARD, ReLook::BG_STANDARD); painter.setBrush(*look->m_brush); QRect editArea(rect.left() + m_widthLineNumbers, rect.top(), - rect.right() - m_widthVScrollBar, rect.bottom() - m_heightHScrollBar); + rect.right() - m_widthVScrollBar, rect.bottom() - m_heightHScrollBar); // Painting the frame of the edit field: painter.drawRect(editArea); // Painting the edit field area (text...) @@ -680,13 +680,13 @@ void ReEdit::paintEvent(QPaintEvent* event) { for (int ix = 0; ix < maxIx; ix++, lineNo++) { QString number = QString::number(lineNo) + ":"; ReLook* look = - lineNo == m_cursorLineNo + 1 ? - lookOf(ReLook::FG_CURRENT_LINE, ReLook::BG_CURRENT_LINE) : - lookStd; + lineNo == m_cursorLineNo + 1 ? + lookOf(ReLook::FG_CURRENT_LINE, ReLook::BG_CURRENT_LINE) : + lookStd; int width = look->m_metrics->width(number); if (ix == 0) y = rect.top() + look->m_metrics->height() - - look->m_metrics->descent(); + - look->m_metrics->descent(); painter.setFont(*look->m_font); painter.setPen(*look->m_pen); painter.drawText(left + m_widthLineNumbers - width - 5, y, number); @@ -694,14 +694,14 @@ void ReEdit::paintEvent(QPaintEvent* event) { } // We paint the cursor: if (m_cursorVisible && m_cursorLineNo >= firstLine - && m_cursorLineNo < firstLine + pageSize) { + && m_cursorLineNo < firstLine + pageSize) { ReParagraph* cursorPara = cursorParagraph(); int col = min(m_cursorCol, cursorPara->m_columns - 1); if (col != -1) col = indexToColumn(col, m_tabWidth, - m_lines->lineAt(m_cursorLineNo)) - m_firstCol; + m_lines->lineAt(m_cursorLineNo)) - m_firstCol; int x = rect.left() + m_widthLineNumbers + 1 - + (col + 1) * lookStd->m_metrics->width('x'); + + (col + 1) * lookStd->m_metrics->width('x'); int y = rect.top() + (m_cursorLineNo - firstLine) * lineHeight; painter.setPen(*look->m_pen); painter.drawLine(x, y, x, y + lineHeight); @@ -709,11 +709,11 @@ void ReEdit::paintEvent(QPaintEvent* event) { int maxLines = max(1, m_lines->lineCount() - pageSize); drawScrollbars(painter, rect, fraction(pageSize, maxLines, 1.0), - fraction(m_firstLine, maxLines, 0.0), - fraction(m_screenWidth, m_maxCols, 1.0), - fraction(m_firstCol, max(0, m_maxCols - m_screenWidth), 0.0)); + fraction(m_firstLine, maxLines, 0.0), + fraction(m_screenWidth, m_maxCols, 1.0), + fraction(m_firstCol, max(0, m_maxCols - m_screenWidth), 0.0)); ReLogger::globalLogger()->logv(LOG_INFO, 3, "draw: %.4f", - double(clock() - start) / CLOCKS_PER_SEC); + double(clock() - start) / CLOCKS_PER_SEC); } /** @@ -773,16 +773,16 @@ void ReEdit::setTabStrings(int tabWidth) { * Constructor. */ ReParagraphs::ReParagraphs() : - m_builders(), - m_firstLine(0), - m_firstCol(0), - m_cursorLineNo(0), - m_cursorCol(-1), - m_lines(NULL), - m_list(), - m_maxCols(0), - m_screenWidth(0), - m_cursorVisible(true) { + m_builders(), + m_firstLine(0), + m_firstCol(0), + m_cursorLineNo(0), + m_cursorCol(-1), + m_lines(NULL), + m_list(), + m_maxCols(0), + m_screenWidth(0), + m_cursorVisible(true) { } /** @@ -824,7 +824,7 @@ void ReParagraphs::clear() { * expanded tabs */ int ReParagraphs::columnToIndex(int column, int tabWidth, - const QString& string) { + const QString& string) { int rc = 0; if (column < 0) rc = -1; @@ -854,7 +854,7 @@ int ReParagraphs::columnToIndex(int column, int tabWidth, ReParagraph* ReParagraphs::cursorParagraph() { ReParagraph* rc = NULL; if (m_cursorLineNo >= m_firstLine - && m_cursorLineNo < m_firstLine + m_list.length()) { + && m_cursorLineNo < m_firstLine + m_list.length()) { rc = m_list.at(m_cursorLineNo - m_firstLine); } return rc; @@ -868,7 +868,7 @@ ReParagraph* ReParagraphs::cursorParagraph() { */ int ReParagraphs::columnToIndex(int cursorCol) { int rc = columnToIndex(cursorCol, m_tabWidth, - m_lines->lineAt(m_cursorLineNo)); + m_lines->lineAt(m_cursorLineNo)); return rc; } @@ -906,7 +906,7 @@ void ReParagraphs::draw(QPainter& painter, int top, int left) { * @return */ int ReParagraphs::indexToColumn(int index, int tabWidth, - const QString& string) { + const QString& string) { int rc = 0; if (index >= 0) { int length = string.length(); @@ -973,13 +973,13 @@ void ReParagraphs::setLines(ReLines* lines) { * @param edit the parent, the edit field */ void ReParagraphBuilder::buildParagraph(ReParagraph& paragraph, int lineNo, - ReEdit* edit) { + ReEdit* edit) { if (paragraph.length() == 0) { int firstCol = edit->m_firstCol; const QString& text = edit->lines().lineAt(lineNo); ReLook* look = edit->lookOf(ReLook::FG_STANDARD, ReLook::BG_STANDARD); ReLook* lookTab = edit->lookOf(ReLook::FG_GREY_LIGHT, - ReLook::BG_STANDARD); + ReLook::BG_STANDARD); paragraph.m_columns = 0; int ixTab; ReEditText* part; @@ -1006,7 +1006,7 @@ void ReParagraphBuilder::buildParagraph(ReParagraph& paragraph, int lineNo, length = tabs.length(); if (cursor + length > firstCol && cursor < maxCol) { if (cursor < firstCol) - tabs = tabs.mid(0, length - firstCol - cursor); + tabs = tabs.left(length - firstCol - cursor); paragraph.append(new ReEditText(tabs, lookTab)); } cursor += length; @@ -1066,14 +1066,14 @@ void ReParagraph::draw(QPainter& painter, int& top, int left) { * Constructor. */ ReMouseCatcher::ReMouseCatcher() : - m_clickObjects(), - m_vScrollBar(new ClickPosition(CO_VSCROLLBAR)), - m_hScrollBar(new ClickPosition(CO_HSCROLLBAR)), - m_hSlider(new ClickPosition(CO_HSLIDER)), - m_vSlider(new ClickPosition(CO_VSLIDER)), - m_lastMousePosition(), - m_lastTopVSlider(0), - m_lastLeftHSlider(0) { + m_clickObjects(), + m_vScrollBar(new ClickPosition(CO_VSCROLLBAR)), + m_hScrollBar(new ClickPosition(CO_HSCROLLBAR)), + m_hSlider(new ClickPosition(CO_HSLIDER)), + m_vSlider(new ClickPosition(CO_VSLIDER)), + m_lastMousePosition(), + m_lastTopVSlider(0), + m_lastLeftHSlider(0) { } /** @@ -1106,17 +1106,19 @@ void ReMouseCatcher::insertClickObject(ReMouseCatcher::ClickPosition* object) { * @return true: the mouse click is inside the horizontal sb */ bool ReMouseCatcher::handleHScrollBar(QMouseEvent* event, bool isDragged, - ReEdit* edit) { + ReEdit* edit) { QPoint pos = event->pos(); bool rc = rectContains(*m_hScrollBar, pos, "hScrollBar") - || (isDragged && m_hScrollBar->contains(m_lastMousePosition)); + || (isDragged && m_hScrollBar->contains(m_lastMousePosition)); if (rc) { if (isDragged) { int distance = pos.x() - m_lastMousePosition.x(); int sliderPos = m_lastLeftHSlider + distance; int moveGap = m_hScrollBar->width() - m_hSlider->width(); double position = moveGap == 0 ? 0.0 : double(sliderPos) / moveGap; - int col = roundInt((edit->m_maxCols - edit->m_screenWidth) * max(0.0, min(position, 1.0))); + int col = roundInt( + (edit->m_maxCols - edit->m_screenWidth) + * max(0.0, min(position, 1.0))); //ReLogger::globalLogger()->logv(LOG_INFO, 4, // "x: %d dist: %d last: %d slPos: %d pos: %.2f gap: %d col: %d / %d scw: %d", // pos.x(), distance, m_lastLeftHSlider, sliderPos, position, moveGap, @@ -1141,10 +1143,10 @@ bool ReMouseCatcher::handleHScrollBar(QMouseEvent* event, bool isDragged, * @return true: the mouse click is inside the vertical sb */ bool ReMouseCatcher::handleVScrollBar(QMouseEvent* event, bool isDragged, - ReEdit* edit) { + ReEdit* edit) { QPoint pos = event->pos(); bool rc = rectContains(*m_vScrollBar, pos, "vScrollBar") - || (isDragged && m_vScrollBar->contains(m_lastMousePosition)); + || (isDragged && m_vScrollBar->contains(m_lastMousePosition)); if (rc) { if (isDragged) { int distance = pos.y() - m_lastMousePosition.y(); @@ -1152,8 +1154,8 @@ bool ReMouseCatcher::handleVScrollBar(QMouseEvent* event, bool isDragged, int moveGap = m_vScrollBar->height() - m_vSlider->height(); double position = moveGap == 0 ? 0.0 : double(sliderPos) / moveGap; int line = roundInt( - (edit->lines().lineCount() - edit->pageSize()) - * max(0.0, min(position, 1.0))); + (edit->lines().lineCount() - edit->pageSize()) + * max(0.0, min(position, 1.0))); edit->reposition(line, edit->m_cursorCol); } else { if (pos.y() < m_vSlider->top()) diff --git a/gui/ReStateStorage.cpp b/gui/ReStateStorage.cpp index b0c88c7..94a4f38 100644 --- a/gui/ReStateStorage.cpp +++ b/gui/ReStateStorage.cpp @@ -155,7 +155,7 @@ bool ReStateStorage::initForRead() { int ixAssignment = line.indexOf('='); if (ixAssignment > 0) { value = line.mid(ixAssignment + 1); - QByteArray key = line.mid(0, ixAssignment).toUtf8(); + QByteArray key = line.left(ixAssignment).toUtf8(); m_map.insert(key, value); } } diff --git a/remodules.hpp b/remodules.hpp index eeadd55..ee1cb35 100644 --- a/remodules.hpp +++ b/remodules.hpp @@ -12,18 +12,19 @@ #define RPLMODULES_HPP enum { - LOC_LOGGER = 101, LOC_CONFIG, LOC_CONTAINER, LOC_EXCEPTION, LOC_TEST, // 105 - LOC_TCPSERVER, - LOC_TCPCLIENT, - LOC_TCPPEER, - LOC_TERMINATOR, - LOC_ASTREE, // 110 - LOC_ASCLASSES, - LOC_LEXER, - LOC_SOURCE, - LOC_VM, - LOC_MFPARSER, // 115 - LOC_TRAVERSER, + LOC_LOGGER = 101, LOC_CONFIG, LOC_CONTAINER, LOC_EXCEPTION, LOC_TEST, // 105 + LOC_TCPSERVER, + LOC_TCPCLIENT, + LOC_TCPPEER, + LOC_TERMINATOR, + LOC_ASTREE, // 110 + LOC_ASCLASSES, + LOC_LEXER, + LOC_SOURCE, + LOC_VM, + LOC_MFPARSER, // 115 + LOC_TRAVERSER, + LOC_STORAGE }; #define LOC_FIRST_OF(moduleNo) (moduleNo*100+1) class RplModules {