Changed: #1307 Added tab view on QMdiArea, new syntax highliter and added base functions for Undo/Redo framework

This commit is contained in:
cemycc 2011-08-11 19:16:46 +03:00
parent 7ea1c96c01
commit f1e55dae35
21 changed files with 79 additions and 80 deletions

View file

@ -35,14 +35,15 @@
using namespace std; using namespace std;
namespace Plugin { namespace TranslationManager {
void CEditorPhrase::open(QString filename) void CEditorPhrase::open(QString filename)
{ {
vector<STRING_MANAGER::TPhrase> phrases; vector<STRING_MANAGER::TPhrase> phrases;
if(readPhraseFile(filename.toStdString(), phrases, false)) if(readPhraseFile(filename.toStdString(), phrases, false))
{ {
text_edit = new QTextEdit(this); text_edit = new CTextEdit(this);
text_edit->setUndoStack(current_stack);
SyntaxHighlighter *highlighter = new SyntaxHighlighter(text_edit); SyntaxHighlighter *highlighter = new SyntaxHighlighter(text_edit);
text_edit->setUndoRedoEnabled(true); text_edit->setUndoRedoEnabled(true);
text_edit->document()->setUndoRedoEnabled(true); text_edit->document()->setUndoRedoEnabled(true);
@ -58,7 +59,6 @@ void CEditorPhrase::open(QString filename)
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
editor_type = Constants::ED_PHRASE; editor_type = Constants::ED_PHRASE;
current_file = filename; current_file = filename;
connect(text_edit->document(), SIGNAL(contentsChange(int, int, int)), this, SLOT(contentsChangeNow(int position, int charsRemoved, int charsAdded)));
connect(text_edit->document(), SIGNAL(contentsChanged()), this, SLOT(docContentsChanged())); connect(text_edit->document(), SIGNAL(contentsChanged()), this, SLOT(docContentsChanged()));
} else { } else {
QErrorMessage error; QErrorMessage error;
@ -67,14 +67,29 @@ void CEditorPhrase::open(QString filename)
} }
} }
void CEditorPhrase::contentsChangeNow(int position, int charsRemoved, int charsAdded) /* void CTextEdit::keyPressEvent(QKeyEvent *event)
{ {
if(charsRemoved > 0) QString chars = event->text();
current_stack->push(new CUndoPhraseRemoveCommand(position-charsRemoved, charsRemoved, text_edit)); int index = textCursor().position();
else if(charsAdded > 0)
current_stack->push(new CUndoPhraseInsertCommand(position, text_edit->toPlainText().right(charsAdded), text_edit)); switch(event->key())
{
case Qt::Key_Backspace:
if (index > 0)
m_undoStack->push(new CUndoPhraseRemoveCommand(index--, 1, this));
break;
case Qt::Key_Delete:
if (index < toPlainText().length())
m_undoStack->push(new CUndoPhraseRemoveCommand(index, 1, this));
break;
default:
if (!chars.isEmpty())
m_undoStack->push(new CUndoPhraseInsertCommand(index, chars, this));
break;
} }
} */
void CEditorPhrase::docContentsChanged() void CEditorPhrase::docContentsChanged()
{ {
setWindowModified(true); setWindowModified(true);

View file

@ -29,17 +29,33 @@
#include <QtGui/QUndoStack> #include <QtGui/QUndoStack>
#include <QtGui/QTextEdit> #include <QtGui/QTextEdit>
#include <QtGui/QSyntaxHighlighter> #include <QtGui/QSyntaxHighlighter>
#include <QtGui/QErrorMessage>
#include <QKeyEvent>
// Project includes // Project includes
#include "translation_manager_editor.h" #include "translation_manager_editor.h"
namespace Plugin { namespace TranslationManager {
class CTextEdit : public QTextEdit
{
Q_OBJECT
private:
QUndoStack* m_undoStack;
public:
CTextEdit(QWidget* parent = 0) : QTextEdit(parent) { }
//void keyPressEvent(QKeyEvent *event);
void setUndoStack(QUndoStack* undoStack)
{
m_undoStack = undoStack;
}
};
class CEditorPhrase : public CEditor class CEditorPhrase : public CEditor
{ {
Q_OBJECT Q_OBJECT
public: public:
QTextEdit *text_edit; CTextEdit *text_edit;
public: public:
CEditorPhrase(QMdiArea* parent) : CEditor(parent) {} CEditorPhrase(QMdiArea* parent) : CEditor(parent) {}
CEditorPhrase() : CEditor() {} CEditorPhrase() : CEditor() {}
@ -49,7 +65,6 @@ public:
void activateWindow(); void activateWindow();
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
public Q_SLOTS: public Q_SLOTS:
void contentsChangeNow(int, int, int);
void docContentsChanged(); void docContentsChanged();
}; };
@ -127,30 +142,12 @@ public:
{ {
HighlightingRule rule; HighlightingRule rule;
keywordFormat.setForeground(Qt::darkBlue); translateStringFormat.setFontWeight(QFont::Bold);
keywordFormat.setFontWeight(QFont::Bold); translateStringFormat.setForeground(Qt::darkMagenta);
QStringList keywordPatterns; rule.pattern = QRegExp("\\[.+\\]");
keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b" rule.format = translateStringFormat;
<< "\\bdouble\\b" << "\\benum\\b" << "\\bexplicit\\b"
<< "\\bfriend\\b" << "\\binline\\b" << "\\bint\\b"
<< "\\blong\\b" << "\\bnamespace\\b" << "\\boperator\\b"
<< "\\bprivate\\b" << "\\bprotected\\b" << "\\bpublic\\b"
<< "\\bshort\\b" << "\\bsignals\\b" << "\\bsigned\\b"
<< "\\bslots\\b" << "\\bstatic\\b" << "\\bstruct\\b"
<< "\\btemplate\\b" << "\\btypedef\\b" << "\\btypename\\b"
<< "\\bunion\\b" << "\\bunsigned\\b" << "\\bvirtual\\b"
<< "\\bvoid\\b" << "\\bvolatile\\b";
Q_FOREACH(const QString &pattern, keywordPatterns) {
rule.pattern = QRegExp(pattern);
rule.format = keywordFormat;
highlightingRules.append(rule); highlightingRules.append(rule);
}
classFormat.setFontWeight(QFont::Bold);
classFormat.setForeground(Qt::darkMagenta);
rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
rule.format = classFormat;
highlightingRules.append(rule);
singleLineCommentFormat.setForeground(Qt::red); singleLineCommentFormat.setForeground(Qt::red);
rule.pattern = QRegExp("//[^\n]*"); rule.pattern = QRegExp("//[^\n]*");
@ -166,7 +163,7 @@ public:
functionFormat.setFontItalic(true); functionFormat.setFontItalic(true);
functionFormat.setForeground(Qt::blue); functionFormat.setForeground(Qt::blue);
rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()"); rule.pattern = QRegExp("\\(.+\\)");
rule.format = functionFormat; rule.format = functionFormat;
highlightingRules.append(rule); highlightingRules.append(rule);
@ -223,6 +220,7 @@ public:
QTextCharFormat multiLineCommentFormat; QTextCharFormat multiLineCommentFormat;
QTextCharFormat quotationFormat; QTextCharFormat quotationFormat;
QTextCharFormat functionFormat; QTextCharFormat functionFormat;
QTextCharFormat translateStringFormat;
}; };
} }

View file

@ -32,7 +32,7 @@
using namespace std; using namespace std;
namespace Plugin { namespace TranslationManager {

View file

@ -38,7 +38,7 @@
#include "translation_manager_editor.h" #include "translation_manager_editor.h"
#include "extract_new_sheet_names.h" #include "extract_new_sheet_names.h"
namespace Plugin { namespace TranslationManager {
class CEditorWorksheet : public CEditor class CEditorWorksheet : public CEditor
{ {

View file

@ -23,7 +23,7 @@ static bool RemoveOlds = false;
namespace Plugin namespace TranslationManager
{ {
TCreatureInfo *ExtractBotNames::getCreature(const std::string &sheetName) TCreatureInfo *ExtractBotNames::getCreature(const std::string &sheetName)

View file

@ -35,7 +35,7 @@ using namespace NLMISC;
using namespace NLLIGO; using namespace NLLIGO;
using namespace STRING_MANAGER; using namespace STRING_MANAGER;
namespace Plugin namespace TranslationManager
{ {
struct TCreatureInfo struct TCreatureInfo

View file

@ -21,7 +21,8 @@ using namespace NLMISC;
using namespace NLLIGO; using namespace NLLIGO;
using namespace STRING_MANAGER; using namespace STRING_MANAGER;
namespace Plugin { namespace TranslationManager
{

View file

@ -35,7 +35,8 @@ using namespace NLMISC;
using namespace NLLIGO; using namespace NLLIGO;
using namespace STRING_MANAGER; using namespace STRING_MANAGER;
namespace Plugin { namespace TranslationManager
{
// *************************************************************************** // ***************************************************************************

View file

@ -3,7 +3,7 @@
#include <QtGui/QMessageBox> #include <QtGui/QMessageBox>
#include <QtNetwork/QFtp> #include <QtNetwork/QFtp>
namespace Plugin namespace TranslationManager
{ {
CFtpSelection::CFtpSelection(QWidget *parent): QDialog(parent) CFtpSelection::CFtpSelection(QWidget *parent): QDialog(parent)
{ {

View file

@ -20,7 +20,7 @@
using namespace std; using namespace std;
namespace Plugin { namespace TranslationManager {
class CFtpSelection : public QDialog class CFtpSelection : public QDialog
{ {

View file

@ -3,7 +3,7 @@
#include "source_selection.h" #include "source_selection.h"
namespace Plugin namespace TranslationManager
{ {

View file

@ -12,7 +12,7 @@
using namespace std; using namespace std;
namespace Plugin namespace TranslationManager
{ {
class CSourceDialog : public QDialog class CSourceDialog : public QDialog

View file

@ -8,7 +8,7 @@
#ifndef TRANSLATION_MANAGER_CONSTANTS_H #ifndef TRANSLATION_MANAGER_CONSTANTS_H
#define TRANSLATION_MANAGER_CONSTANTS_H #define TRANSLATION_MANAGER_CONSTANTS_H
namespace Plugin namespace TranslationManager
{ {
namespace Constants namespace Constants
{ {

View file

@ -25,7 +25,7 @@
#include <QtGui/QUndoStack> #include <QtGui/QUndoStack>
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
namespace Plugin { namespace TranslationManager {
class CEditor : public QMdiSubWindow { class CEditor : public QMdiSubWindow {
Q_OBJECT Q_OBJECT

View file

@ -44,7 +44,7 @@
#include "ftp_selection.h" #include "ftp_selection.h"
namespace Plugin namespace TranslationManager
{ {
CMainWindow::CMainWindow(QWidget *parent) CMainWindow::CMainWindow(QWidget *parent)
@ -592,30 +592,6 @@ bool CMainWindow::isPhraseEditor(QString filename)
} }
} }
/* void CMainWindow::keyPressEvent(QKeyEvent *event)
{
CEditorPhrase* editor = qobject_cast<CEditorPhrase*>(_ui.mdiArea->currentSubWindow());
QString chars = event->text();
int index = editor->text_edit->textCursor().position();
switch (event->key())
{
case Qt::Key_Backspace:
if (index > 0)
m_undoStack->push(new CUndoPhraseRemoveCommand(index--, 1, editor->text_edit));
break;
case Qt::Key_Delete:
if (index < editor->text_edit->toPlainText().length())
m_undoStack->push(new CUndoPhraseRemoveCommand(index, 1, editor->text_edit));
break;
default:
if (!chars.isEmpty())
m_undoStack->push(new CUndoPhraseInsertCommand(index, chars, editor->text_edit));
break;
}
} */
bool CCoreListener::closeMainWindow() const bool CCoreListener::closeMainWindow() const
{ {
bool okToClose = true; bool okToClose = true;

View file

@ -52,7 +52,7 @@ class QWidget;
using namespace std; using namespace std;
namespace Plugin namespace TranslationManager
{ {
class CMainWindow : public QMainWindow class CMainWindow : public QMainWindow

View file

@ -18,7 +18,14 @@
<item row="0" column="0"> <item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QMdiArea" name="mdiArea"/> <widget class="QMdiArea" name="mdiArea">
<property name="viewMode">
<enum>QMdiArea::TabbedView</enum>
</property>
<property name="documentMode">
<bool>true</bool>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>

View file

@ -37,7 +37,7 @@
#include <QtGui/QAction> #include <QtGui/QAction>
#include <QtGui/QMenuBar> #include <QtGui/QMenuBar>
namespace Plugin namespace TranslationManager
{ {
TranslationManagerPlugin::~TranslationManagerPlugin() TranslationManagerPlugin::~TranslationManagerPlugin()
{ {
@ -137,8 +137,9 @@ ExtensionSystem::IPluginSpec *TranslationManagerPlugin::pluginByName(const QStri
if (spec->name() == name) if (spec->name() == name)
return spec; return spec;
return 0; return 0;
} }
} }
Q_EXPORT_PLUGIN(Plugin::TranslationManagerPlugin) Q_EXPORT_PLUGIN(TranslationManager::TranslationManagerPlugin)

View file

@ -42,7 +42,7 @@ namespace ExtensionSystem
class IPluginSpec; class IPluginSpec;
} }
namespace Plugin namespace TranslationManager
{ {
class CTranslationManagerContext; class CTranslationManagerContext;

View file

@ -28,7 +28,7 @@
// Project includes // Project includes
#include "../core/icore.h" #include "../core/icore.h"
namespace Plugin namespace TranslationManager
{ {
QString lastDir = "."; QString lastDir = ".";

View file

@ -26,7 +26,7 @@
class QWidget; class QWidget;
namespace Plugin namespace TranslationManager
{ {
/** /**
@class CTranslationManagerSettingsPage @class CTranslationManagerSettingsPage