2014-09-26 08:46:48 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 by Amaury Pouly
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2013-08-21 18:16:26 +00:00
|
|
|
#include <QWidget>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QAction>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMenuBar>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QTabBar>
|
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "regtab.h"
|
2014-04-07 09:28:04 +00:00
|
|
|
#include "regedit.h"
|
2013-08-21 18:16:26 +00:00
|
|
|
|
2014-09-18 19:36:17 +00:00
|
|
|
/**
|
|
|
|
* DocumentTab
|
|
|
|
*/
|
|
|
|
void DocumentTab::OnModified(bool modified)
|
|
|
|
{
|
|
|
|
if(m_tab)
|
|
|
|
m_tab->SetTabModified(this, modified);
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
void DocumentTab::SetTabWidget(DocumentTabWidget *tab)
|
2014-09-27 11:28:44 +00:00
|
|
|
{
|
|
|
|
m_tab = tab;
|
|
|
|
SetTabName(m_tabname);
|
|
|
|
}
|
|
|
|
|
2014-09-18 19:36:17 +00:00
|
|
|
void DocumentTab::SetTabName(const QString& name)
|
|
|
|
{
|
2014-09-27 11:28:44 +00:00
|
|
|
m_tabname = name;
|
2014-09-18 19:36:17 +00:00
|
|
|
if(m_tab)
|
|
|
|
m_tab->SetTabName(this, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-02-06 15:08:43 +00:00
|
|
|
* DocumentTabWidget
|
2014-09-18 19:36:17 +00:00
|
|
|
*/
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
DocumentTabWidget::DocumentTabWidget()
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
|
|
|
setMovable(true);
|
|
|
|
setTabsClosable(true);
|
|
|
|
connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(OnCloseTab(int)));
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
void DocumentTabWidget::SetTabModified(DocumentTab *doc, bool modified)
|
2014-09-18 19:36:17 +00:00
|
|
|
{
|
|
|
|
int index = indexOf(doc->GetWidget());
|
|
|
|
if(modified)
|
|
|
|
setTabIcon(index, QIcon::fromTheme("document-save"));
|
|
|
|
else
|
|
|
|
setTabIcon(index, QIcon());
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
void DocumentTabWidget::SetTabName(DocumentTab *doc, const QString& name)
|
2014-09-18 19:36:17 +00:00
|
|
|
{
|
|
|
|
setTabText(indexOf(doc->GetWidget()), name);
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
bool DocumentTabWidget::CloseTab(int index)
|
2013-08-21 18:16:26 +00:00
|
|
|
{
|
2014-02-04 16:35:09 +00:00
|
|
|
QWidget *w = this->widget(index);
|
2014-04-07 09:28:04 +00:00
|
|
|
DocumentTab *doc = dynamic_cast< DocumentTab* >(w);
|
|
|
|
if(doc->Quit())
|
|
|
|
{
|
|
|
|
removeTab(index);
|
|
|
|
delete w;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
void DocumentTabWidget::OnCloseTab(int index)
|
2014-04-07 09:28:04 +00:00
|
|
|
{
|
|
|
|
CloseTab(index);
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 19:36:17 +00:00
|
|
|
/**
|
|
|
|
* MainWindow
|
|
|
|
*/
|
|
|
|
|
2013-08-21 18:16:26 +00:00
|
|
|
MainWindow::MainWindow(Backend *backend)
|
|
|
|
:m_backend(backend)
|
|
|
|
{
|
2016-02-07 21:48:40 +00:00
|
|
|
QAction *new_regtab_act = new QAction(YIconManager::Get()->GetIcon(YIconManager::DocumentNew),
|
|
|
|
tr("Register &Tab"), this);
|
|
|
|
QAction *new_regedit_act = new QAction(YIconManager::Get()->GetIcon(YIconManager::DocumentEdit),
|
|
|
|
tr("Register &Editor"), this);
|
|
|
|
QAction *load_desc_act = new QAction(YIconManager::Get()->GetIcon(YIconManager::DocumentOpen),
|
|
|
|
tr("&Soc Description"), this);
|
|
|
|
QAction *quit_act = new QAction(YIconManager::Get()->GetIcon(YIconManager::ApplicationExit),
|
|
|
|
tr("&Quit"), this);
|
|
|
|
QAction *about_act = new QAction(YIconManager::Get()->GetIcon(YIconManager::HelpAbout),
|
|
|
|
tr("&About"), this);
|
|
|
|
QAction *about_qt_act = new QAction(YIconManager::Get()->GetIcon(YIconManager::HelpAbout),
|
|
|
|
tr("About &Qt"), this);
|
2013-08-21 18:16:26 +00:00
|
|
|
|
|
|
|
connect(new_regtab_act, SIGNAL(triggered()), this, SLOT(OnNewRegTab()));
|
2014-04-07 09:28:04 +00:00
|
|
|
connect(new_regedit_act, SIGNAL(triggered()), this, SLOT(OnNewRegEdit()));
|
2013-08-21 18:16:26 +00:00
|
|
|
connect(load_desc_act, SIGNAL(triggered()), this, SLOT(OnLoadDesc()));
|
|
|
|
connect(quit_act, SIGNAL(triggered()), this, SLOT(OnQuit()));
|
|
|
|
connect(about_act, SIGNAL(triggered()), this, SLOT(OnAbout()));
|
2014-02-09 01:17:14 +00:00
|
|
|
connect(about_qt_act, SIGNAL(triggered()), this, SLOT(OnAboutQt()));
|
2013-08-21 18:16:26 +00:00
|
|
|
|
2016-02-07 21:48:40 +00:00
|
|
|
QMenu *app_menu = new QMenu;
|
|
|
|
QMenu *file_menu = app_menu->addMenu(tr("&File"));
|
|
|
|
QMenu *new_submenu = file_menu->addMenu(YIconManager::Get()->GetIcon(YIconManager::DocumentNew), "&New");
|
|
|
|
QMenu *load_submenu = file_menu->addMenu(YIconManager::Get()->GetIcon(YIconManager::DocumentOpen), "&Load");
|
2013-08-21 18:16:26 +00:00
|
|
|
file_menu->addAction(quit_act);
|
|
|
|
|
|
|
|
new_submenu->addAction(new_regtab_act);
|
2014-04-07 09:28:04 +00:00
|
|
|
new_submenu->addAction(new_regedit_act);
|
2013-08-21 18:16:26 +00:00
|
|
|
|
|
|
|
load_submenu->addAction(load_desc_act);
|
|
|
|
|
2016-02-07 21:48:40 +00:00
|
|
|
QMenu *about_menu = app_menu->addMenu(tr("&About"));
|
2013-08-21 18:16:26 +00:00
|
|
|
about_menu->addAction(about_act);
|
2014-02-09 01:17:14 +00:00
|
|
|
about_menu->addAction(about_qt_act);
|
2013-08-21 18:16:26 +00:00
|
|
|
|
2016-02-06 15:08:43 +00:00
|
|
|
m_tab = new DocumentTabWidget();
|
|
|
|
m_tab->setTabOpenable(true);
|
|
|
|
m_tab->setTabOpenMenu(new_submenu);
|
2016-02-07 21:48:40 +00:00
|
|
|
m_tab->setOtherMenu(app_menu);
|
2013-08-21 18:16:26 +00:00
|
|
|
|
|
|
|
setCentralWidget(m_tab);
|
|
|
|
|
|
|
|
ReadSettings();
|
2016-02-07 21:48:40 +00:00
|
|
|
#ifdef HAVE_HWSTUB
|
|
|
|
/* acquire hwstub manager */
|
|
|
|
HWStubManager::Get()->setParent(this);
|
|
|
|
#endif
|
|
|
|
/* acquire icon manager */
|
|
|
|
YIconManager::Get()->setParent(this);
|
2013-12-24 14:25:42 +00:00
|
|
|
|
|
|
|
OnNewRegTab();
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ReadSettings()
|
|
|
|
{
|
|
|
|
restoreGeometry(Settings::Get()->value("mainwindow/geometry").toByteArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::WriteSettings()
|
|
|
|
{
|
|
|
|
Settings::Get()->setValue("mainwindow/geometry", saveGeometry());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::OnQuit()
|
|
|
|
{
|
2014-02-09 01:17:14 +00:00
|
|
|
close();
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::OnAbout()
|
|
|
|
{
|
2016-02-06 15:08:43 +00:00
|
|
|
QString soc_desc_ver = QString("%1.%2.%3").arg(soc_desc::MAJOR_VERSION)
|
|
|
|
.arg(soc_desc::MINOR_VERSION).arg(soc_desc::REVISION_VERSION);
|
2014-05-01 22:32:41 +00:00
|
|
|
QMessageBox::about(this, "About",
|
|
|
|
"<h1>QEditor</h1>"
|
2016-02-07 21:48:40 +00:00
|
|
|
"<h2>Version " APP_VERSION "</h2>"
|
2014-05-01 22:32:41 +00:00
|
|
|
"<p>Written by Amaury Pouly</p>"
|
|
|
|
"<p>Libraries:</p>"
|
2014-12-14 10:53:55 +00:00
|
|
|
"<ul><li>soc_desc: " + soc_desc_ver + "</li>"
|
2014-05-01 22:32:41 +00:00
|
|
|
#ifdef HAVE_HWSTUB
|
2016-02-07 21:48:40 +00:00
|
|
|
"<li>hwstub: " HWSTUB_VERSION "</li>"
|
2014-05-01 22:32:41 +00:00
|
|
|
#else
|
|
|
|
"<li>hwstub: not compiled in</li>"
|
|
|
|
#endif
|
|
|
|
"</ul>");
|
2014-02-09 01:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::OnAboutQt()
|
|
|
|
{
|
|
|
|
QMessageBox::aboutQt(this);
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2014-04-07 09:28:04 +00:00
|
|
|
if(!Quit())
|
|
|
|
return event->ignore();
|
2013-08-21 18:16:26 +00:00
|
|
|
WriteSettings();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::OnLoadDesc()
|
|
|
|
{
|
|
|
|
QFileDialog *fd = new QFileDialog(this);
|
2016-02-06 15:08:43 +00:00
|
|
|
QStringList filters;
|
|
|
|
filters << "XML files (*.xml)";
|
|
|
|
filters << "All files (*)";
|
|
|
|
fd->setNameFilters(filters);
|
2013-08-21 18:16:26 +00:00
|
|
|
fd->setFileMode(QFileDialog::ExistingFiles);
|
2014-04-07 09:28:04 +00:00
|
|
|
fd->setDirectory(Settings::Get()->value("loaddescdir", QDir::currentPath()).toString());
|
2013-08-21 18:16:26 +00:00
|
|
|
if(fd->exec())
|
|
|
|
{
|
|
|
|
QStringList filenames = fd->selectedFiles();
|
|
|
|
for(int i = 0; i < filenames.size(); i++)
|
|
|
|
if(!m_backend->LoadSocDesc(filenames[i]))
|
|
|
|
{
|
|
|
|
QMessageBox msg;
|
|
|
|
msg.setText(QString("Cannot load ") + filenames[i]);
|
|
|
|
msg.exec();
|
|
|
|
}
|
2014-04-07 09:28:04 +00:00
|
|
|
Settings::Get()->setValue("loaddescdir", fd->directory().absolutePath());
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-27 11:28:44 +00:00
|
|
|
void MainWindow::AddTab(DocumentTab *doc)
|
2014-04-07 09:28:04 +00:00
|
|
|
{
|
2014-09-27 11:28:44 +00:00
|
|
|
m_tab->setCurrentIndex(m_tab->addTab(doc->GetWidget(), ""));
|
2014-09-18 19:36:17 +00:00
|
|
|
doc->SetTabWidget(m_tab);
|
2014-04-07 09:28:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 18:16:26 +00:00
|
|
|
void MainWindow::OnNewRegTab()
|
|
|
|
{
|
2014-09-27 11:28:44 +00:00
|
|
|
AddTab(new RegTab(m_backend, this));
|
2014-04-07 09:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::OnNewRegEdit()
|
|
|
|
{
|
2014-09-27 11:28:44 +00:00
|
|
|
AddTab(new RegEdit(m_backend, this));
|
2014-04-07 09:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MainWindow::Quit()
|
|
|
|
{
|
|
|
|
while(m_tab->count() > 0)
|
|
|
|
{
|
|
|
|
if(!m_tab->CloseTab(0))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2013-08-21 18:16:26 +00:00
|
|
|
}
|