NewMainWindow prototype - close, minimize

.. very basic, no icons. Just to be able to close
   gracefully. Need to get same level of functionality
   on windows and macOS.
This commit is contained in:
Mark Liversedge
2020-03-29 13:46:24 +01:00
parent 102b5dff15
commit c9bca752cc
2 changed files with 43 additions and 1 deletions

View File

@@ -11,6 +11,8 @@ constexpr double gl_minheight = 700;
constexpr double gl_toolbarheight = 46;
constexpr double gl_searchwidth = 350;
constexpr double gl_searchheight = 26;
constexpr double gl_quitheight = 26;
constexpr double gl_quitwidth = 26;
NewMainWindow::NewMainWindow(QApplication *app) : QMainWindow(NULL), app(app)
{
@@ -50,7 +52,13 @@ NewMainWindow::setupToolbar()
searchbox->setFixedHeight(gl_searchheight * dpiXFactor);
searchbox->setFrame(QFrame::NoFrame);
searchbox->setStyleSheet("background: white; border-radius: 7px;");
searchbox->setPlaceholderText(tr("search or /expression... "));
searchbox->setPlaceholderText(tr(" Search or type a command "));
// spacer to balance the minimize and close buttons
QWidget *balanceSpacer = new QWidget(this);
balanceSpacer->setFixedSize(gl_quitwidth*dpiXFactor * 2, gl_quitheight*dpiYFactor);
balanceSpacer->setVisible(true);
balanceSpacer->setAutoFillBackground(false);
QWidget *leftSpacer = new QWidget(this);
leftSpacer->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
@@ -62,10 +70,31 @@ NewMainWindow::setupToolbar()
rightSpacer->setVisible(true);
rightSpacer->setAutoFillBackground(false);
toolbar->addWidget(balanceSpacer);
toolbar->addWidget(leftSpacer);
toolbar->addWidget(searchbox);
toolbar->addWidget(rightSpacer);
// and close push buttons on the right
minimisebutton = new QPushButton(this);
minimisebutton->setFlat(true);
minimisebutton->setFixedSize(gl_quitwidth * dpiXFactor, gl_quitheight *dpiXFactor);
minimisebutton->setStyleSheet("background: lightGray; color: white;");
minimisebutton->setText("_"); // fix with icon later
toolbar->addWidget(minimisebutton);
// and close push buttons on the right
quitbutton = new QPushButton(this);
quitbutton->setFlat(true);
quitbutton->setFixedSize(gl_quitwidth * dpiXFactor, gl_quitheight *dpiXFactor);
quitbutton->setStyleSheet("background: lightGray; color: white;");
quitbutton->setText("X"); // fix with icon later
toolbar->addWidget(quitbutton);
// connect up
connect(quitbutton, SIGNAL(clicked()), this, SLOT(close()));
connect(minimisebutton, SIGNAL(clicked()), this, SLOT(minimizeWindow()));
toolbar->show();
}
@@ -113,3 +142,9 @@ void
NewMainWindow::mouseMoveEvent(QMouseEvent *event) {
move(event->globalX()-clickPos.x(),event->globalY()-clickPos.y());
}
void
NewMainWindow::minimizeWindow()
{
setWindowState(Qt::WindowMinimized);
}

View File

@@ -2,9 +2,12 @@
#include <QToolBar>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QPushButton>
class NewMainWindow : public QMainWindow
{
Q_OBJECT
public:
NewMainWindow(QApplication *app);
@@ -24,6 +27,9 @@ class NewMainWindow : public QMainWindow
// set initial geometry, screen etc
void initialPosition();
public slots:
void minimizeWindow();
private:
QApplication *app;
@@ -31,6 +37,7 @@ class NewMainWindow : public QMainWindow
QVBoxLayout *layout;
QToolBar *toolbar;
QLineEdit *searchbox;
QPushButton *quitbutton, *minimisebutton;
QPoint clickPos;
};