You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
4.8 KiB
C++

#include "cmainwindow.h"
#include "ui_cmainwindow.h"
#include <QSettings>
#include <QStyle>
#include <QDebug>
cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::cMainWindow),
m_splashScreen(lpSplashScreen),
m_progressBar(nullptr),
m_fileMenu(nullptr),
m_fileToolBar(nullptr),
m_fileNewAction(nullptr)
{
initUI();
createActions();
loadSystemFonts(m_splashScreen);
}
cMainWindow::~cMainWindow()
{
delete ui;
}
void cMainWindow::closeEvent(QCloseEvent *event)
{
QSettings settings;
settings.setValue("main/width", QVariant::fromValue(size().width()));
settings.setValue("main/height", QVariant::fromValue(size().height()));
settings.setValue("main/x", QVariant::fromValue(x()));
settings.setValue("main/y", QVariant::fromValue(y()));
if(this->isMaximized())
settings.setValue("main/maximized", QVariant::fromValue(true));
else
settings.setValue("main/maximized", QVariant::fromValue(false));
event->accept();
}
void cMainWindow::initUI()
{
QSettings settings;
ui->setupUi(this);
if(!settings.value("main/maximized").toBool())
{
qint32 iX = settings.value("main/x", QVariant::fromValue(-1)).toInt();
qint32 iY = settings.value("main/y", QVariant::fromValue(-1)).toInt();
qint32 iWidth = settings.value("main/width", QVariant::fromValue(-1)).toInt();
qint32 iHeight = settings.value("main/height", QVariant::fromValue(-1)).toInt();
if(iWidth != -1 && iHeight != -1)
resize(iWidth, iHeight);
if(iX != -1 && iY != -1)
move(iX, iY);
}
m_progressBar = new QProgressBar(this);
m_progressBar->setVisible(false);
ui->m_statusBar->addPermanentWidget(m_progressBar);
QIcon::setThemeName("GNOME");
}
void cMainWindow::createActions()
{
setToolButtonStyle(Qt::ToolButtonFollowStyle);
createFileActions();
createContextActions();
// connect(ui->m_lpFileList, &cTreeView::deleteEntrys, this, &cMainWindow::onDeleteEntrys);
// connect(ui->m_lpThumbnailSize, &QSlider::valueChanged, this, &cMainWindow::onThumbnailSize);
}
void cMainWindow::createContextActions()
{
}
void cMainWindow::createFileActions()
{
m_fileMenu = menuBar()->addMenu(tr("&File"));
m_fileToolBar = addToolBar(tr("File Actions"));
const QIcon newIcon = QIcon::fromTheme("document-new");
m_fileNewAction = m_fileMenu->addAction(newIcon, tr("&New"), this, &cMainWindow::onFileNew);
m_fileToolBar->addAction(m_fileNewAction);
m_fileNewAction->setPriority(QAction::LowPriority);
m_fileNewAction->setShortcut(QKeySequence::New);
// m_lpFileToolBar = addToolBar("file");
// const QIcon openIcon = QIcon::fromTheme("document-open");
// m_lpOpenFileAction = m_lpFileToolBar->addAction(openIcon, tr("&Open..."), this, &cMainWindow::onAddFile);
// m_lpOpenFileAction->setShortcut(QKeySequence::Open);
// const QIcon openDirectoryIcon = QIcon::fromTheme("folder");
// m_lpOpenDirectoryAction = m_lpFileToolBar->addAction(openIcon, tr("&Open Folder..."), this, &cMainWindow::onAddFolder);
// m_lpListToolBar = addToolBar("list");
// const QIcon deleteIcon = QIcon::fromTheme("edit-delete");
// m_lpDeleteAction = m_lpListToolBar->addAction(deleteIcon, tr("&Delete"), this, &cMainWindow::onDeleteEntrys);
// m_lpDeleteAction->setShortcut(QKeySequence::Delete);
// const QIcon clearIcon = QIcon::fromTheme("edit-clear");
// m_lpClearAction = m_lpListToolBar->addAction(clearIcon, tr("&Clear"), this, &cMainWindow::onClearList);
// m_lpActionToolBar = addToolBar("action");
// const QIcon convertIcon = QIcon::fromTheme("system-run");
// m_lpConvertAction = m_lpActionToolBar->addAction(convertIcon, tr("&Convert"), this, &cMainWindow::onConvert);
// m_lpConvertAction->setShortcut(QKeySequence::Delete);
// const QIcon stopIcon = QIcon::fromTheme("process-stop");
// m_lpStopAction = m_lpActionToolBar->addAction(stopIcon, tr("&Stop"), this, &cMainWindow::onStop);
}
void cMainWindow::loadSystemFonts(cSplashScreen* splashScreen)
{
m_fontViewList.clearAll();
QStringList families = m_fontDatabase.families();
int cnt = 0;
if(splashScreen)
splashScreen->setMax(families.count());
else
m_progressBar->setMaximum(families.count());
for(const QString& family : families)
{
if(splashScreen)
{
splashScreen->setProgress(cnt);
splashScreen->showStatusMessage("loading " + family + " ...");
}
else
{
m_progressBar->setValue(cnt);
ui->m_statusBar->showMessage("loading " + family + " ...");
}
cFontView* lpFontView = new cFontView(this);
lpFontView->setText("The quick brown fox jumps over the lazy dog");
lpFontView->setFont(QFont(family, 16));
lpFontView->setBackground(Qt::white);
lpFontView->setForeground(Qt::black);
ui->m_fontListLayout->addWidget(lpFontView);
m_fontViewList.add(lpFontView);
cnt++;
}
if(!splashScreen)
ui->m_statusBar->showMessage("done.", 2000);
}
void cMainWindow::onFileNew()
{
loadSystemFonts();
}