2015-12-06 10:18:31 +00:00
|
|
|
|
|
|
|
#include "dialogue.hpp"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QSplitter>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QStackedWidget>
|
2015-12-06 11:06:28 +00:00
|
|
|
#include <QListWidgetItem>
|
2015-12-06 10:18:31 +00:00
|
|
|
|
|
|
|
#include "../../model/prefs/state.hpp"
|
|
|
|
|
|
|
|
void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main)
|
|
|
|
{
|
|
|
|
mList = new QListWidget (main);
|
|
|
|
mList->setMinimumWidth (50);
|
|
|
|
mList->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
mList->setSelectionBehavior (QAbstractItemView::SelectItems);
|
|
|
|
|
|
|
|
main->addWidget (mList);
|
|
|
|
|
2015-12-06 11:06:28 +00:00
|
|
|
QFontMetrics metrics (QApplication::font());
|
|
|
|
|
|
|
|
int maxWidth = 1;
|
|
|
|
|
|
|
|
for (std::vector<std::pair<std::string, std::string> >::const_iterator iter (mCategories.begin());
|
|
|
|
iter!=mCategories.end(); ++iter)
|
|
|
|
{
|
|
|
|
QString label = QString::fromUtf8 (iter->first.c_str());
|
|
|
|
maxWidth = std::max (maxWidth, metrics.width (label));
|
|
|
|
|
|
|
|
mList->addItem (label);
|
|
|
|
}
|
|
|
|
|
|
|
|
mList->setMaximumWidth (maxWidth + 10);
|
|
|
|
|
2015-12-06 10:18:31 +00:00
|
|
|
/// \todo connect to selection signal
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSVPrefs::Dialogue::buildContentArea (QSplitter *main)
|
|
|
|
{
|
|
|
|
mContent = new QStackedWidget (main);
|
|
|
|
mContent->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
main->addWidget (mContent);
|
|
|
|
}
|
|
|
|
|
2015-12-06 11:06:28 +00:00
|
|
|
CSVPrefs::Dialogue::Dialogue() : mCategories (CSMPrefs::get().listCategories())
|
2015-12-06 10:18:31 +00:00
|
|
|
{
|
|
|
|
setWindowTitle ("User Settings");
|
|
|
|
|
|
|
|
setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
|
|
|
|
|
|
|
setMinimumSize (600, 400);
|
|
|
|
|
|
|
|
QSplitter *main = new QSplitter (this);
|
|
|
|
|
|
|
|
setCentralWidget (main);
|
|
|
|
buildCategorySelector (main);
|
|
|
|
buildContentArea (main);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSVPrefs::Dialogue::closeEvent (QCloseEvent *event)
|
|
|
|
{
|
|
|
|
QMainWindow::closeEvent (event);
|
|
|
|
|
|
|
|
CSMPrefs::State::get().save();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSVPrefs::Dialogue::show()
|
|
|
|
{
|
|
|
|
if (QWidget *active = QApplication::activeWindow())
|
|
|
|
{
|
|
|
|
// place at the centre of the window with focus
|
|
|
|
QSize size = active->size();
|
|
|
|
move (active->geometry().x()+(size.width() - frameGeometry().width())/2,
|
|
|
|
active->geometry().y()+(size.height() - frameGeometry().height())/2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// otherwise place at the centre of the screen
|
|
|
|
QPoint screenCenter = QApplication::desktop()->screenGeometry().center();
|
|
|
|
move (screenCenter - QPoint(frameGeometry().width()/2, frameGeometry().height()/2));
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget::show();
|
|
|
|
}
|