Changed: #1307 Added some features and making little modifications

This commit is contained in:
cemycc 2011-08-04 17:19:17 +03:00
parent 5a599bc7ff
commit 9bca613c47
7 changed files with 681 additions and 613 deletions

View file

@ -21,6 +21,8 @@
#include <QtCore/qfileinfo.h>
#include <QtGui/QMessageBox>
#include <QtGui/QCloseEvent>
#include <QtGui/QAction>
#include <QtGui/QMenu>
// Project includes
#include "editor_worksheet.h"
@ -99,6 +101,7 @@ void CEditorWorksheet::open(QString filename)
// set editor signals
connect(table_editor, SIGNAL(itemChanged(QTableWidgetItem*) ), this, SLOT(worksheetEditorChanged(QTableWidgetItem*)));
connect(table_editor, SIGNAL(itemDoubleClicked(QTableWidgetItem*) ), this, SLOT(worksheetEditorCellEntered(QTableWidgetItem*)));
connect (table_editor,SIGNAL(customContextMenuRequested(const QPoint &)), this,SLOT(contextMenuEvent(QContextMenuEvent*)));
} else {
QErrorMessage error;
error.showMessage("This file is not a worksheet file.");
@ -107,6 +110,23 @@ void CEditorWorksheet::open(QString filename)
}
void CEditorWorksheet::contextMenuEvent(QContextMenuEvent *e)
{
QAction *insertRowAct = new QAction("Insert new row", this);
connect(insertRowAct, SIGNAL(triggered()), this, SLOT(insertRow()));
QAction *deleteRowAct = new QAction("Delete row", this);
connect(deleteRowAct, SIGNAL(triggered()), this, SLOT(deleteRow()));
QMenu *contextMenu = new QMenu(this);
contextMenu->addAction(insertRowAct);
contextMenu->addAction(deleteRowAct);
contextMenu->exec( e->globalPos() );
delete contextMenu;
contextMenu = NULL;
}
void CEditorWorksheet::activateWindow()
{
showMaximized();
@ -332,6 +352,7 @@ void CEditorWorksheet::extractBotNames(list<string> filters, string level_design
if(modified)
{
setWindowModified(true);
table_editor->scrollToBottom();
}
}

View file

@ -65,6 +65,7 @@ private Q_SLOTS:
void worksheetEditorChanged(QTableWidgetItem * item);
void insertRow();
void deleteRow();
void contextMenuEvent(QContextMenuEvent *e);
};
@ -123,6 +124,7 @@ public:
{
QTableWidgetItem* item = new QTableWidgetItem();
m_table->setItem(m_rowID, j, item);
m_table->scrollToBottom();
}
}

View file

@ -1,3 +1,4 @@
// Translation Manager Plugin - OVQT Plugin <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2011 Emanuel Costea <cemycc@gmail.com>
@ -123,16 +124,14 @@ void CMainWindow::createToolbar()
mergeSingleFileAct->setStatusTip(tr("Merge worksheet file from local or remote directory"));
connect(mergeSingleFileAct, SIGNAL(triggered()), this, SLOT(mergeSingleFile()));
// Windows menu
windowMenu = new QMenu(tr("&Windows..."), _ui.toolBar);
windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL));
Core::ICore *core = Core::ICore::instance();
Core::IMenuManager *menuManager = core->menuManager();
windowMenu = menuManager->menuBar()->addMenu("Window");
updateWindowsList();
_ui.toolBar->addAction(windowMenu->menuAction());
connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList()));
// Undo, Redo actions
// -----------------------------
Core::ICore *core = Core::ICore::instance();
Core::IMenuManager *menuManager = core->menuManager();
QAction* undoAction = menuManager->action(Core::Constants::UNDO);
if (undoAction != 0)
_ui.toolBar->addAction(undoAction);
@ -147,10 +146,15 @@ void CMainWindow::updateToolbar(QMdiSubWindow *window)
if(_ui.mdiArea->subWindowList().size() > 0)
if(QString(window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor
{
QAction *insertRowAct = windowMenu->addAction("Insert new row");
//setContextMenuPolicy(Qt::ActionsContextMenu);
QAction *insertRowAct = new QAction("Insert new row", this);
connect(insertRowAct, SIGNAL(triggered()), window, SLOT(insertRow()));
QAction *deleteRowAct = windowMenu->addAction("Delete row");
//addAction(insertRowAct);
windowMenu->addAction(insertRowAct);
QAction *deleteRowAct = new QAction("Delete row", this);
connect(deleteRowAct, SIGNAL(triggered()), window, SLOT(deleteRow()));
//addAction(deleteRowAct);
windowMenu->addAction(deleteRowAct);
}
}
@ -167,7 +171,7 @@ void CMainWindow::setActiveSubWindow(QWidget* window)
void CMainWindow::activeSubWindowChanged()
{
//TODO: nothing to be done here atm
}
void CMainWindow::updateWindowsList()
@ -187,10 +191,11 @@ void CMainWindow::updateWindowsList()
} else {
action_text = tr("%1 %2").arg(i + 1).arg(window_file);
}
QAction *action = windowMenu->addAction(action_text);
QAction *action = new QAction(action_text, this);
action->setCheckable(true);
action->setChecked(subWindows.at(i) == current_window);
connect(action, SIGNAL(triggered()), windowMapper, SLOT(map()));
windowMenu->addAction(action);
windowMapper->setMapping(action, subWindows.at(i));
}
}
@ -589,7 +594,35 @@ bool CMainWindow::isPhraseEditor(QString filename)
bool CCoreListener::closeMainWindow() const
{
return true;
Q_FOREACH(QMdiSubWindow *subWindow, m_MainWindow->_ui.mdiArea->subWindowList())
{
CEditor *currentEditor = qobject_cast<CEditor*>(subWindow);
if(subWindow->isWindowModified())
{
QMessageBox msgBox;
msgBox.setText(tr("The document has been modified ( %1 ).").arg(currentEditor->windowFilePath()));
msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
switch (ret)
{
case QMessageBox::Save:
currentEditor->save();
return true;
break;
case QMessageBox::Discard:
return true;
break;
case QMessageBox::Cancel:
return false;
break;
default:
break;
}
}
}
}
} /* namespace Plugin */

View file

@ -62,8 +62,9 @@ public:
CMainWindow(QWidget *parent = 0);
virtual ~CMainWindow() {}
QUndoStack *m_undoStack;
public:
Ui::CMainWindow _ui;
private:
Ui::CMainWindow _ui;
// actions
QAction *openAct;
QAction *saveAct;
@ -111,13 +112,20 @@ class CCoreListener : public Core::ICoreListener
{
Q_OBJECT
public:
CCoreListener(QObject *parent = 0): ICoreListener(parent) {}
virtual ~CCoreListener() {}
CCoreListener(CMainWindow* mainWindow, QObject *parent = 0): ICoreListener(parent)
{
m_MainWindow = mainWindow;
}
virtual ~CCoreListener() {}
virtual bool closeMainWindow() const;
public:
CMainWindow *m_MainWindow;
};
} // namespace Plugin

View file

@ -53,10 +53,12 @@ bool TranslationManagerPlugin::initialize(ExtensionSystem::IPluginManager *plugi
{
Q_UNUSED(errorString);
_plugMan = pluginManager;
// create the mainwindow
CMainWindow *mainWindow = new CMainWindow();
addAutoReleasedObject(new CTranslationManagerSettingsPage(this));
addAutoReleasedObject(new CTranslationManagerContext(this));
addAutoReleasedObject(new CCoreListener(this));
addAutoReleasedObject(new CTranslationManagerContext(mainWindow, this));
addAutoReleasedObject(new CCoreListener(mainWindow, this));
return true;
}
@ -75,6 +77,8 @@ void TranslationManagerPlugin::extensionsInitialized()
helpMenu->insertAction(aboutQtAction, aboutTManPlugin);
}
void TranslationManagerPlugin::setNelContext(NLMISC::INelContext *nelContext)
{
#ifdef NL_OS_WINDOWS

View file

@ -82,9 +82,9 @@ class CTranslationManagerContext: public Core::IContext
{
Q_OBJECT
public:
CTranslationManagerContext(QObject *parent = 0): IContext(parent)
CTranslationManagerContext(CMainWindow* mainWindow, QObject *parent = 0): IContext(parent)
{
m_MainWindow = new CMainWindow();
m_MainWindow = mainWindow;
}
virtual ~CTranslationManagerContext() {}