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();
#include <QFileDialog>
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));
proj = lastProjects.at(ix);
}
if (!proj.isEmpty())
- m_project = new Project(proj);
+ changeProject(proj);
}
ui->setupUi(this);
*/
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);
}
/**
*/
void MainWindow::changeWorkspace(const QString& path) {
delete m_workspace;
- m_workspace = new Workspace(path);
+ m_workspace = new Workspace(path, m_logger);
}
/**
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;
}
/**
ProjectSelection dialog(this);
dialog.exec();
}
+ReLogger* MainWindow::logger() const {
+ return m_logger;
+}
/**
* Returns the current workspace.
#include <QMainWindow>
#ifndef REBASE_HPP
-#include "base/rebase.hpp"
+#include "reditor.hpp"
#endif
namespace Ui {
class MainWindow;
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();
ReFile* m_file;
Storage* m_project;
Storage* m_workspace;
+ ReLogger* m_logger;
};
#endif // MAINWINDOW_HPP
/*
- * 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) {
}
/*
- * 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
class Project: public Storage {
public:
- Project(const QString& path);
+ Project(const QString& path, ReLogger* logger);
};
#endif // PROJECT_HPP
/*
- * 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"
error("does not exists: " + name);
else {
if (file.isDir())
- m_mainWindow->openProject(name);
+ m_mainWindow->changeProject(name);
else
m_mainWindow->openFile(name);
close();
*/
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()) {
/*
- * 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
/*
- * 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
/*
- * 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.<br>
+ * 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 <code>list</code> (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<Property*>* list = m_chapters.value(chapter, NULL);
+ if (list == NULL) {
+ m_chapters.insert(chapter, list = new QList<Property*>());
+ }
+ list->append(property);
+}
+
/*
- * 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<const char*, Property*> m_settings;
+ QMap<QByteArray, QList<Property*>*> m_chapters;
+ ReLogger* m_logger;
};
#endif // STORAGE_HPP
/*
- * 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]"));
}
/*
- * 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
class Workspace: public Storage {
public:
- Workspace(const QString& path);
+ Workspace(const QString& path, ReLogger* logger);
};
#endif // WORKSPACE_HPP
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);
}
}
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();
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;
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));
}
}
}
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);
}
/**
/*
- * 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"
* @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) {
}
/**
* @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) {
}
* @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);
* @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);
* @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)
* @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);
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)
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);
}
/**
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;
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;
*/
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)
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 {
* @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) {
*/
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();
}
}
} 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
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;
}
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...)
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);
}
// 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);
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);
}
/**
* 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) {
}
/**
* expanded tabs
*/
int ReParagraphs::columnToIndex(int column, int tabWidth,
- const QString& string) {
+ const QString& string) {
int rc = 0;
if (column < 0)
rc = -1;
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;
*/
int ReParagraphs::columnToIndex(int cursorCol) {
int rc = columnToIndex(cursorCol, m_tabWidth,
- m_lines->lineAt(m_cursorLineNo));
+ m_lines->lineAt(m_cursorLineNo));
return rc;
}
* @return
*/
int ReParagraphs::indexToColumn(int index, int tabWidth,
- const QString& string) {
+ const QString& string) {
int rc = 0;
if (index >= 0) {
int length = string.length();
* @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;
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;
* 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) {
}
/**
* @return <code>true</code>: 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,
* @return <code>true</code>: 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();
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())
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);
}
}
#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 {