Clean up mainwindow initialization

This commit is contained in:
Marcus Huderle 2018-09-24 19:46:09 -05:00
parent 083e8e6101
commit afc25805d3
4 changed files with 45 additions and 24 deletions

View file

@ -33,22 +33,46 @@ MainWindow::MainWindow(QWidget *parent) :
QApplication::setWindowIcon(QIcon(":/icons/porymap-icon-1.ico"));
ui->setupUi(this);
ui->newEventToolButton->initButton();
connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString)));
new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
editor = new Editor(ui);
connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects()));
connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
connect(editor, SIGNAL(tilesetChanged(QString)), this, SLOT(onTilesetChanged(QString)));
connect(editor, SIGNAL(warpEventDoubleClicked(QString,QString)), this, SLOT(openWarpMap(QString,QString)));
connect(editor, SIGNAL(currentMetatilesSelectionChanged()), this, SLOT(currentMetatilesSelectionChanged()));
this->initExtraSignals();
this->initExtraShortcuts();
this->loadUserSettings();
this->initEditor();
this->openRecentProject();
on_toolButton_Paint_clicked();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::initExtraShortcuts() {
new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
}
void MainWindow::initExtraSignals() {
connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString)));
}
void MainWindow::initEditor() {
this->editor = new Editor(ui);
connect(this->editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects()));
connect(this->editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
connect(this->editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
connect(this->editor, SIGNAL(tilesetChanged(QString)), this, SLOT(onTilesetChanged(QString)));
connect(this->editor, SIGNAL(warpEventDoubleClicked(QString,QString)), this, SLOT(openWarpMap(QString,QString)));
connect(this->editor, SIGNAL(currentMetatilesSelectionChanged()), this, SLOT(currentMetatilesSelectionChanged()));
}
void MainWindow::loadUserSettings() {
QSettings settings;
if (settings.contains("cursor_mode") && settings.value("cursor_mode") == "0") {
ui->actionBetter_Cursors->setChecked(false);
}
}
void MainWindow::openRecentProject() {
QSettings settings;
QString key = "recent_projects";
if (settings.contains(key)) {
@ -58,15 +82,6 @@ MainWindow::MainWindow(QWidget *parent) :
openProject(default_dir);
}
}
if (settings.contains("cursor_mode") && settings.value("cursor_mode") == "0") {
ui->actionBetter_Cursors->setChecked(false);
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::setStatusBarMessage(QString message, int timeout/* = 0*/) {

View file

@ -145,6 +145,11 @@ private:
void checkToolButtons();
void scaleMapView(int);
void initExtraShortcuts();
void initExtraSignals();
void initEditor();
void loadUserSettings();
void openRecentProject();
};
enum MapListUserRoles {

View file

@ -10,9 +10,10 @@ NewEventToolButton::NewEventToolButton(QWidget *parent) :
setPopupMode(QToolButton::MenuButtonPopup);
QObject::connect(this, SIGNAL(triggered(QAction*)),
this, SLOT(setDefaultAction(QAction*)));
this->init();
}
void NewEventToolButton::initButton()
void NewEventToolButton::init()
{
// Add a context menu to select different types of map events.
this->newObjectAction = new QAction("New Object", this);

View file

@ -9,7 +9,6 @@ class NewEventToolButton : public QToolButton
Q_OBJECT
public:
explicit NewEventToolButton(QWidget *parent = nullptr);
void initButton();
QString getSelectedEventType();
public slots:
void newObject();
@ -32,6 +31,7 @@ private:
QAction *newSignAction;
QAction *newHiddenItemAction;
QAction *newSecretBaseAction;
void init();
};
#endif // NEWEVENTTOOLBUTTON_H