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 72b338d6f4
commit a9778a62a1
21 changed files with 79 additions and 80 deletions

View file

@ -35,14 +35,15 @@
using namespace std;
namespace Plugin {
namespace TranslationManager {
void CEditorPhrase::open(QString filename)
{
vector<STRING_MANAGER::TPhrase> phrases;
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);
text_edit->setUndoRedoEnabled(true);
text_edit->document()->setUndoRedoEnabled(true);
@ -58,7 +59,6 @@ void CEditorPhrase::open(QString filename)
setAttribute(Qt::WA_DeleteOnClose);
editor_type = Constants::ED_PHRASE;
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()));
} else {
QErrorMessage error;
@ -67,13 +67,28 @@ void CEditorPhrase::open(QString filename)
}
}
void CEditorPhrase::contentsChangeNow(int position, int charsRemoved, int charsAdded)
/* void CTextEdit::keyPressEvent(QKeyEvent *event)
{
if(charsRemoved > 0)
current_stack->push(new CUndoPhraseRemoveCommand(position-charsRemoved, charsRemoved, text_edit));
else if(charsAdded > 0)
current_stack->push(new CUndoPhraseInsertCommand(position, text_edit->toPlainText().right(charsAdded), text_edit));
}
QString chars = event->text();
int index = textCursor().position();
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()
{

View file

@ -29,17 +29,33 @@
#include <QtGui/QUndoStack>
#include <QtGui/QTextEdit>
#include <QtGui/QSyntaxHighlighter>
#include <QtGui/QErrorMessage>
#include <QKeyEvent>
// Project includes
#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
{
Q_OBJECT
public:
QTextEdit *text_edit;
CTextEdit *text_edit;
public:
CEditorPhrase(QMdiArea* parent) : CEditor(parent) {}
CEditorPhrase() : CEditor() {}
@ -49,7 +65,6 @@ public:
void activateWindow();
void closeEvent(QCloseEvent *event);
public Q_SLOTS:
void contentsChangeNow(int, int, int);
void docContentsChanged();
};
@ -127,30 +142,12 @@ public:
{
HighlightingRule rule;
keywordFormat.setForeground(Qt::darkBlue);
keywordFormat.setFontWeight(QFont::Bold);
QStringList keywordPatterns;
keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b"
<< "\\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;
translateStringFormat.setFontWeight(QFont::Bold);
translateStringFormat.setForeground(Qt::darkMagenta);
rule.pattern = QRegExp("\\[.+\\]");
rule.format = translateStringFormat;
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);
rule.pattern = QRegExp("//[^\n]*");
@ -166,7 +163,7 @@ public:
functionFormat.setFontItalic(true);
functionFormat.setForeground(Qt::blue);
rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()");
rule.pattern = QRegExp("\\(.+\\)");
rule.format = functionFormat;
highlightingRules.append(rule);
@ -223,6 +220,7 @@ public:
QTextCharFormat multiLineCommentFormat;
QTextCharFormat quotationFormat;
QTextCharFormat functionFormat;
QTextCharFormat translateStringFormat;
};
}

View file

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

View file

@ -38,7 +38,7 @@
#include "translation_manager_editor.h"
#include "extract_new_sheet_names.h"
namespace Plugin {
namespace TranslationManager {
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)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -44,7 +44,7 @@
#include "ftp_selection.h"
namespace Plugin
namespace TranslationManager
{
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 okToClose = true;

View file

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

View file

@ -18,7 +18,14 @@
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<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>
</layout>
</item>

View file

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

View file

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

View file

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

View file

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