Skip to content

Commit

Permalink
gui: show maximized and always center workspace after window resize.
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-0x7C6 committed Dec 6, 2019
1 parent 02978c5 commit e660f99
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
int main(int argc, char *argv[]) {
QApplication application(argc, argv);
MainWindow window;
window.show();
window.showMaximized();

return application.exec();
}
2 changes: 0 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ MainWindow::MainWindow(QWidget *parent)
const auto metric = sheet::make_metric(category);
get_label(*m_ui, category)->setText(QString("%1 <font color=\"gray\">(%2 mm x %3 mm)</font>").arg(name(category), QString::number(metric.w), QString::number(metric.h)));
}

resize(1600, 800);
}

MainWindow::~MainWindow() {
Expand Down
18 changes: 13 additions & 5 deletions src/widgets/graphics-view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

GraphicsView::GraphicsView(QWidget *parent)
: QGraphicsView(parent) {
setViewportUpdateMode(QGraphicsView::ViewportUpdateMode::MinimalViewportUpdate);
}

void GraphicsView::showEvent(QShowEvent *) {
//setViewport(new QGLWidget(QGLFormat(QGL::SingleBuffer))); //moved to showEvent because of strange random artefacts
setViewportUpdateMode(QGraphicsView::ViewportUpdateMode::MinimalViewportUpdate);
centerOn(0.0, 0.0);
void GraphicsView::resizeEvent(QResizeEvent *event) {
center();
QGraphicsView::resizeEvent(event);
}

void GraphicsView::wheelEvent(QWheelEvent *) {
void GraphicsView::showEvent(QShowEvent *event) {
center();
QGraphicsView::showEvent(event);
}

void GraphicsView::wheelEvent(QWheelEvent *) {} //eat event

void GraphicsView::center() {
centerOn(0.0, 0.0);
}
4 changes: 4 additions & 0 deletions src/widgets/graphics-view.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class GraphicsView : public QGraphicsView {
GraphicsView(QWidget *parent = nullptr);

protected:
void resizeEvent(QResizeEvent *) final;
void showEvent(QShowEvent *) final;
void wheelEvent(QWheelEvent *) final;

private:
void center();
};

0 comments on commit e660f99

Please sign in to comment.