mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-17 13:01:41 +00:00
Changed: #1307 Added tab view on QMdiArea, new syntax highliter and added base functions for Undo/Redo framework
This commit is contained in:
parent
7ea1c96c01
commit
f1e55dae35
21 changed files with 79 additions and 80 deletions
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
highlightingRules.append(rule);
|
||||
}
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
namespace Plugin {
|
||||
namespace TranslationManager {
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include "translation_manager_editor.h"
|
||||
#include "extract_new_sheet_names.h"
|
||||
|
||||
namespace Plugin {
|
||||
namespace TranslationManager {
|
||||
|
||||
class CEditorWorksheet : public CEditor
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ static bool RemoveOlds = false;
|
|||
|
||||
|
||||
|
||||
namespace Plugin
|
||||
namespace TranslationManager
|
||||
{
|
||||
|
||||
TCreatureInfo *ExtractBotNames::getCreature(const std::string &sheetName)
|
||||
|
|
|
@ -35,7 +35,7 @@ using namespace NLMISC;
|
|||
using namespace NLLIGO;
|
||||
using namespace STRING_MANAGER;
|
||||
|
||||
namespace Plugin
|
||||
namespace TranslationManager
|
||||
{
|
||||
|
||||
struct TCreatureInfo
|
||||
|
|
|
@ -21,7 +21,8 @@ using namespace NLMISC;
|
|||
using namespace NLLIGO;
|
||||
using namespace STRING_MANAGER;
|
||||
|
||||
namespace Plugin {
|
||||
namespace TranslationManager
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -35,7 +35,8 @@ using namespace NLMISC;
|
|||
using namespace NLLIGO;
|
||||
using namespace STRING_MANAGER;
|
||||
|
||||
namespace Plugin {
|
||||
namespace TranslationManager
|
||||
{
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtNetwork/QFtp>
|
||||
namespace Plugin
|
||||
namespace TranslationManager
|
||||
{
|
||||
CFtpSelection::CFtpSelection(QWidget *parent): QDialog(parent)
|
||||
{
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
namespace Plugin {
|
||||
namespace TranslationManager {
|
||||
|
||||
class CFtpSelection : public QDialog
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "source_selection.h"
|
||||
|
||||
namespace Plugin
|
||||
namespace TranslationManager
|
||||
{
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
namespace Plugin
|
||||
namespace TranslationManager
|
||||
{
|
||||
|
||||
class CSourceDialog : public QDialog
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#ifndef TRANSLATION_MANAGER_CONSTANTS_H
|
||||
#define TRANSLATION_MANAGER_CONSTANTS_H
|
||||
|
||||
namespace Plugin
|
||||
namespace TranslationManager
|
||||
{
|
||||
namespace Constants
|
||||
{
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <QtGui/QUndoStack>
|
||||
#include <QtCore/QFileInfo>
|
||||
|
||||
namespace Plugin {
|
||||
namespace TranslationManager {
|
||||
|
||||
class CEditor : public QMdiSubWindow {
|
||||
Q_OBJECT
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -52,7 +52,7 @@ class QWidget;
|
|||
|
||||
using namespace std;
|
||||
|
||||
namespace Plugin
|
||||
namespace TranslationManager
|
||||
{
|
||||
|
||||
class CMainWindow : public QMainWindow
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace ExtensionSystem
|
|||
class IPluginSpec;
|
||||
}
|
||||
|
||||
namespace Plugin
|
||||
namespace TranslationManager
|
||||
{
|
||||
|
||||
class CTranslationManagerContext;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
// Project includes
|
||||
#include "../core/icore.h"
|
||||
|
||||
namespace Plugin
|
||||
namespace TranslationManager
|
||||
{
|
||||
|
||||
QString lastDir = ".";
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
class QWidget;
|
||||
|
||||
namespace Plugin
|
||||
namespace TranslationManager
|
||||
{
|
||||
/**
|
||||
@class CTranslationManagerSettingsPage
|
||||
|
|
Loading…
Reference in a new issue