Commit 7d5e1cc2 authored by Alexander A. Maly's avatar Alexander A. Maly

Headers optimization in editor

And warnings cleaning.
parent 0ce695fb
......@@ -2,6 +2,7 @@
#define EDITOR_INTERFACE
#include <QtPlugin>
class QUrl;
namespace Shared
{
......
......@@ -3,6 +3,7 @@
#include <kumir2/analizerinterface.h>
#include <kumir2/analizer_sourcefileinterface.h>
#include <QStringList>
#include <QRect>
#include <QUndoCommand>
......
......@@ -26,6 +26,8 @@
#include <QLayout>
#include <QPainter>
#include <QPaintEvent>
#include <QTextCodec>
#include <QApplication>
namespace Editor
......@@ -589,12 +591,12 @@ void EditorInstance::updateFromAnalizer()
for (int i = 0; i < (int)doc_->linesCount(); i++) {
oldIndents[i] = doc_->indentAt(i);
}
for (int i = 0; i < (int)doc_->linesCount(); i++) {
for (unsigned int i = 0; i < doc_->linesCount(); i++) {
int oldIndent = oldIndents[i];
if (i < ranks.size()) {
if (i < (unsigned int) ranks.size()) {
doc_->setIndentRankAt(i, ranks[i]);
}
if (i < props.size()) {
if (i < (unsigned int) props.size()) {
doc_->setHighlightAt(i, props[i].toList());
}
doc_->at(i).multipleStatementsInLine = analizerInstance_->multipleStatementsInLine(i);
......
......@@ -9,9 +9,7 @@
#include "editor.h"
#include <stdint.h>
#ifdef Q_OS_UNIX
//#include <unistd.h>
#endif
#include <math.h>
#include <QLabel>
#include <QMenu>
......@@ -21,6 +19,7 @@
#include <QContextMenuEvent>
#include <QMouseEvent>
#include <QDrag>
#include <QMimeData>
namespace Editor
......@@ -177,7 +176,7 @@ void EditorPlane::mousePressEvent(QMouseEvent *e)
const int editableAreaLeftBorder = leftTextAreaPosition();
// Right border of editable area
const int editableAreaRightBorder = rightTextAreaPosition();
// const int editableAreaRightBorder = rightTextAreaPosition();
// Force text cursor (managed primarily from keyboard) to temporary hide
editor_->cursor()->setViewMode(TextCursor::VM_Hidden);
......@@ -1799,9 +1798,9 @@ uint EditorPlane::leftTextAreaPosition() const
uint EditorPlane::rightTextAreaPosition() const
{
const uint left = leftTextAreaPosition();
const uint areaWidth = widthInChars() * charWidth();
const uint result = left + areaWidth;
uint left = leftTextAreaPosition();
uint areaWidth = widthInChars() * charWidth();
uint result = left + areaWidth;
return result;
}
......@@ -2280,10 +2279,13 @@ void EditorPlane::paintLineNumbers(QPainter *p, const QRect &rect)
// Visible line number accounting Y-scroll offset
uint realLineNumber = i + qMax(0, -offset().y()) / lineHeight();
if (-1 != highlightedTextLineNumber_ && highlightedTextLineNumber_ + 1 == realLineNumber) {
paintLineHighlight(p, QRect(
if (
-1 != highlightedTextLineNumber_ &&
(uint) (highlightedTextLineNumber_ + 1) == realLineNumber
) {
paintLineHighlight(
p,
QRect(
0,
highlightedTextLineNumber_ * lineHeight() + 1 + offset().y(),
charWidth() * 5 + lockSymbolOffset + breakpointPaneWidth,
......@@ -2304,7 +2306,10 @@ void EditorPlane::paintLineNumbers(QPainter *p, const QRect &rect)
textColor = textColor.darker(); // make it more contrast to real line numbers
}
p->setPen(textColor);
if (-1 != highlightedTextLineNumber_ && highlightedTextLineNumber_ + 1 == realLineNumber) {
if (
-1 != highlightedTextLineNumber_ &&
(uint) (highlightedTextLineNumber_ + 1) == realLineNumber
) {
p->setPen(QColor(Qt::black));
}
// Calculate number width to align it centered
......@@ -2317,21 +2322,25 @@ void EditorPlane::paintLineNumbers(QPainter *p, const QRect &rect)
if (editor_->plugin_->teacherMode_) {
// Paint 'lock' symbol to the left of line number
const QRect lockSymbolRect(
QRect lockSymbolRect(
0,
i * lineHeight(),
LOCK_SYMBOL_WIDTH,
lineHeight()
);
if (realLineNumber < editor_->document()->linesCount() &&
editor_->document()->isProtected(realLineNumber)) {
if (
realLineNumber < editor_->document()->linesCount() &&
editor_->document()->isProtected(realLineNumber)
) {
// Draw 'locked' symbol if line is protected
paintLockSymbol(p, true, lockSymbolRect);
}
if (realLineNumber == highlightedLockSymbolLineNumber_ &&
realLineNumber < editor_->document()->linesCount() &&
!editor_->document()->isProtected(realLineNumber)) {
if (
realLineNumber == (uint) highlightedLockSymbolLineNumber_ &&
realLineNumber < (uint) editor_->document()->linesCount() &&
!editor_->document()->isProtected(realLineNumber)
) {
// Draw 'locked' symbol outline in case of mouse over
paintLockSymbol(p, false, lockSymbolRect);
}
......@@ -2499,7 +2508,7 @@ void EditorPlane::paintMarginText(QPainter *p, const QRect &rect)
// Set corresponding text color
QColor color = editor_->document()->marginAt(i).text.length() > 0
? marginColor : errorColor ;
if (darkness / 3 <= 127 && highlightedTextLineNumber_ == i) {
if (darkness / 3 <= 127 && (uint) highlightedTextLineNumber_ == i) {
color = QColor(Qt::black);
}
p->setPen(color);
......@@ -2599,22 +2608,21 @@ void EditorPlane::paintText(QPainter *p, const QRect &rect)
.toBool()
) {
// Check for dark background
const QColor bgColor = palette().color(QPalette::Base);
QColor bgColor = palette().color(QPalette::Base);
int darkness = bgColor.red() + bgColor.green() + bgColor.blue();
if (darkness / 3 <= 127) {
// Invert color for dark backround
if (i != highlightedTextLineNumber_) {
if (i != (uint) highlightedTextLineNumber_) {
p->setBrush(Qt::white);
}
}
}
p->setPen(Qt::NoPen);
for (uint j = 0; j < indent; j++) {
const uint dotSize = qMin(lineHeight() / 3u,
charWidth() / 3u);
const uint dotX = j * charWidth() * 2 + (charWidth() - dotSize);
const uint dotY = y - lineHeight() + (lineHeight() - dotSize);
const QRect dotRect(dotX, dotY, dotSize, dotSize);
uint dotSize = qMin(lineHeight() / 3u, charWidth() / 3u);
uint dotX = j * charWidth() * 2 + (charWidth() - dotSize);
uint dotY = y - lineHeight() + (lineHeight() - dotSize);
QRect dotRect(dotX, dotY, dotSize, dotSize);
p->drawRect(dotRect);
}
......@@ -2654,8 +2662,8 @@ void EditorPlane::paintText(QPainter *p, const QRect &rect)
// Set proper format for lexem type and current character
setProperFormat(p, curType, text[j]);
if (i == highlightedTextLineNumber_) {
const QColor bgColor = palette().color(QPalette::Base);
if (i == (uint) highlightedTextLineNumber_) {
QColor bgColor = palette().color(QPalette::Base);
int darkness = bgColor.red() + bgColor.green() + bgColor.blue();
if (darkness / 3 <= 127) {
p->setPen(QColor(Qt::black));
......@@ -2669,7 +2677,7 @@ void EditorPlane::paintText(QPainter *p, const QRect &rect)
// If line is highlighted, then make text some darker
// for better accessibility
if (highlightedTextLineNumber_ == i) {
if ((uint) highlightedTextLineNumber_ == i) {
p->setPen(p->pen().color().darker());
}
......
......@@ -6,8 +6,8 @@
#include <kumir2/analizer_instanceinterface.h>
#include <kumir2/analizerinterface.h>
#include <QtCore>
class QLabel;
class QMimeData;
namespace Editor
......
......@@ -8,6 +8,7 @@
#include <QtPlugin>
#include <QApplication>
#include <QFontDatabase>
#include <QDebug>
namespace Editor
......
......@@ -2,6 +2,7 @@
#define EDITOR_PLUGIN_H
#include "macro.h"
#include <QVector>
#include <QFont>
#include <kumir2/editorinterface.h>
......
#include <QtCore>
#include <QtXml>
#include "macro.h"
#include <QFile>
#include <QIODevice>
#include <QTextStream>
namespace Editor
{
......
......@@ -2,10 +2,12 @@
#define MACRO_H
#include "keycommand.h"
#include <QtCore>
#include <QList>
#include <QSharedPointer>
#include <QDomElement>
class QAction;
class QDomElement;
class QDomDocument;
......
......@@ -2,109 +2,116 @@
#include "ui_macrolisteditor.h"
#include "macroeditor.h"
#include <QDir>
namespace Editor {
namespace Editor
{
MacroListEditor::MacroListEditor(const QDir & resourcesRoot, QWidget *parent) :
QDialog(parent),
ui(new Ui::MacroListEditor)
MacroListEditor::MacroListEditor(const QDir &resourcesRoot, QWidget *parent) :
QDialog(parent),
ui(new Ui::MacroListEditor)
{
ui->setupUi(this);
ui->btnRemove->setIcon(QIcon(resourcesRoot.absoluteFilePath("find-close.png")));
ui->btnEdit->setIcon(QIcon(resourcesRoot.absoluteFilePath("find-options.png")));
ui->btnRemove->setEnabled(false);
ui->btnEdit->setEnabled(false);
ui->setupUi(this);
ui->btnRemove->setIcon(QIcon(resourcesRoot.absoluteFilePath("find-close.png")));
ui->btnEdit->setIcon(QIcon(resourcesRoot.absoluteFilePath("find-options.png")));
ui->btnRemove->setEnabled(false);
ui->btnEdit->setEnabled(false);
connect(ui->listWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this, SLOT(handleItemChanged(QListWidgetItem*,QListWidgetItem*)));
connect(ui->listWidget, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
this, SLOT(handleItemChanged(QListWidgetItem *, QListWidgetItem *)));
connect(ui->btnRemove, SIGNAL(clicked()), this, SLOT(removeMacro()));
connect(ui->btnEdit, SIGNAL(clicked()), this, SLOT(editMacro()));
connect(ui->btnRemove, SIGNAL(clicked()), this, SLOT(removeMacro()));
connect(ui->btnEdit, SIGNAL(clicked()), this, SLOT(editMacro()));
}
void MacroListEditor::handleItemChanged(QListWidgetItem *current, QListWidgetItem * )
{
ui->btnRemove->setEnabled(current != nullptr);
ui->btnEdit->setEnabled(current != nullptr);
void MacroListEditor::handleItemChanged(
QListWidgetItem *current,
QListWidgetItem *
) {
ui->btnRemove->setEnabled(current != nullptr);
ui->btnEdit->setEnabled(current != nullptr);
}
void MacroListEditor::initialize(const QList<QSharedPointer<Macro> > &macros,
const QList<QSharedPointer<Macro> > &systemMacros)
{
ui->btnRemove->setEnabled(false);
ui->btnEdit->setEnabled(false);
ui->listWidget->clear();
macros_ = macros;
systemMacros_ = systemMacros;
for (int i=0; i<macros_.size(); i++) {
QSharedPointer<Macro> macro = macros_[i];
QListWidgetItem * item = new QListWidgetItem;
QString text = macro->title.trimmed();
if (!macro->key.isNull()) {
text += QString(" (Esc, ") + macro->key + ")";
}
item->setText(text);
ui->listWidget->addItem(item);
}
if (ui->listWidget->count() > 0) {
ui->listWidget->setCurrentRow(0);
}
void MacroListEditor::initialize(
const QList<QSharedPointer<Macro> > &macros,
const QList<QSharedPointer<Macro> > &systemMacros
) {
ui->btnRemove->setEnabled(false);
ui->btnEdit->setEnabled(false);
ui->listWidget->clear();
macros_ = macros;
systemMacros_ = systemMacros;
for (int i = 0; i < macros_.size(); i++) {
QSharedPointer<Macro> macro = macros_[i];
QListWidgetItem *item = new QListWidgetItem;
QString text = macro->title.trimmed();
if (!macro->key.isNull()) {
text += QString(" (Esc, ") + macro->key + ")";
}
item->setText(text);
ui->listWidget->addItem(item);
}
if (ui->listWidget->count() > 0) {
ui->listWidget->setCurrentRow(0);
}
}
void MacroListEditor::removeMacro()
{
if (!ui->listWidget->currentItem())
return;
int index = ui->listWidget->currentRow();
QListWidgetItem * item = ui->listWidget->takeItem(index);
delete item;
macros_.removeAt(index);
if (!ui->listWidget->currentItem()) {
return;
}
int index = ui->listWidget->currentRow();
QListWidgetItem *item = ui->listWidget->takeItem(index);
delete item;
macros_.removeAt(index);
}
void MacroListEditor::editMacro()
{
if (!ui->listWidget->currentItem())
return;
QListWidgetItem * item = ui->listWidget->currentItem();
int index = ui->listWidget->currentRow();
QSharedPointer<Macro> macro = macros_[index];
MacroEditor * editor = new MacroEditor(this);
editor->setWindowTitle(tr("Edit recorded keyboard sequence..."));
QList<QSharedPointer<Macro> > allMacros = systemMacros_ + macros_;
QString usedLetters;
QStringList usedNames;
foreach(QSharedPointer<Macro> m, allMacros) {
if (!m->key.isNull()) {
usedLetters.push_back(m->key);
usedNames.push_back(m->title);
}
}
editor->setUsedSymbols(usedLetters, usedNames);
editor->setMacro(macro);
if (editor->exec() == QDialog::Accepted) {
QString text = macro->title.trimmed();
if (!macro->key.isNull()) {
text += " (" + prefix_ + macro->key + ")";
}
item->setText(text);
macros_[index] = macro;
}
if (!ui->listWidget->currentItem()) {
return;
}
QListWidgetItem *item = ui->listWidget->currentItem();
int index = ui->listWidget->currentRow();
QSharedPointer<Macro> macro = macros_[index];
MacroEditor *editor = new MacroEditor(this);
editor->setWindowTitle(tr("Edit recorded keyboard sequence..."));
QList<QSharedPointer<Macro> > allMacros = systemMacros_ + macros_;
QString usedLetters;
QStringList usedNames;
foreach (QSharedPointer<Macro> m, allMacros) {
if (!m->key.isNull()) {
usedLetters.push_back(m->key);
usedNames.push_back(m->title);
}
}
editor->setUsedSymbols(usedLetters, usedNames);
editor->setMacro(macro);
if (editor->exec() == QDialog::Accepted) {
QString text = macro->title.trimmed();
if (!macro->key.isNull()) {
text += " (" + prefix_ + macro->key + ")";
}
item->setText(text);
macros_[index] = macro;
}
}
QList<QSharedPointer<Macro> > MacroListEditor::result() const
{
return macros_;
return macros_;
}
MacroListEditor::~MacroListEditor()
{
delete ui;
delete ui;
}
} // namespace Editor
......@@ -4,36 +4,39 @@
#include <macro.h>
#include <QDialog>
#include <QListWidgetItem>
class QListWidgetItem;
class QDir;
namespace Editor {
namespace Editor
{
namespace Ui {
namespace Ui
{
class MacroListEditor;
}
class MacroListEditor : public QDialog
{
Q_OBJECT
Q_OBJECT
public:
explicit MacroListEditor(const QDir & resourcesRoot, QWidget *parent = 0);
void initialize(const QList<QSharedPointer<Macro> > & macros,
const QList<QSharedPointer<Macro> > &systemMacros);
QList<QSharedPointer<Macro> > result() const;
~MacroListEditor();
explicit MacroListEditor(const QDir &resourcesRoot, QWidget *parent = 0);
void initialize(const QList<QSharedPointer<Macro> > &macros,
const QList<QSharedPointer<Macro> > &systemMacros);
QList<QSharedPointer<Macro> > result() const;
~MacroListEditor();
private slots:
void handleItemChanged(QListWidgetItem * current, QListWidgetItem*);
void removeMacro();
void editMacro();
void handleItemChanged(QListWidgetItem *current, QListWidgetItem *);
void removeMacro();
void editMacro();
private:
Ui::MacroListEditor *ui;
QList<QSharedPointer<Macro> > macros_;
QList<QSharedPointer<Macro> > systemMacros_;
QString prefix_;
Ui::MacroListEditor *ui;
QList<QSharedPointer<Macro> > macros_;
QList<QSharedPointer<Macro> > systemMacros_;
QString prefix_;
};
......
......@@ -248,7 +248,7 @@ void SettingsPage::init()
settings_->value(KeyFreeCursorMovement, DefaultFreeCursorMovement)
.toUInt();
if (freeCursorMovement < ui->freeCursorPositioning->count()) {
if (freeCursorMovement < (uint) ui->freeCursorPositioning->count()) {
ui->freeCursorPositioning->setCurrentIndex(freeCursorMovement);
}
......@@ -339,7 +339,7 @@ void SettingsPage::resetToDefaults()
uint freeCursorMovement = DefaultFreeCursorMovement;
if (freeCursorMovement < ui->freeCursorPositioning->count()) {
if (freeCursorMovement < (uint) ui->freeCursorPositioning->count()) {
ui->freeCursorPositioning->setCurrentIndex(freeCursorMovement);
}
......
......@@ -3,7 +3,6 @@
#include <kumir2-libs/extensionsystem/settings.h>
#include <QtCore>
#include <QWidget>
class QToolButton;
......
......@@ -7,6 +7,7 @@
#include <QKeyEvent>
#include <QFocusEvent>
#include <QAction>
#include <QDebug>
namespace Editor
{
......
......@@ -4,7 +4,6 @@
#include <kumir2-libs/extensionsystem/settings.h>
#include <kumir2-libs/docbookviewer/docbookview.h>
#include <QtCore>
#include <QStandardItem>
#include <QStyledItemDelegate>
......
......@@ -6,6 +6,7 @@
#include "settingspage.h"
#include <kumir2-libs/extensionsystem/pluginmanager.h>
#include <QApplication>
#include <QDebug>
namespace Editor
{
......
......@@ -8,6 +8,7 @@
#include <kumir2-libs/extensionsystem/pluginmanager.h>
#include <QUndoStack>
#include <QTextCodec>
namespace Editor
{
......@@ -359,7 +360,7 @@ void TextDocument::setPlainText(const QString &t)
int TextDocument::hiddenLineStart() const
{
int result = -1;
for (int i = 0; i < (uint) data_.size(); i++) {
for (int i = 0; i < data_.size(); i++) {
if (data_[i].hidden) {
result = i;
break;
......
This diff is collapsed.
#ifndef UTILS_H
#define UTILS_H
#include <Qt>
#include <QString>
namespace Editor
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment