Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Esteban Blanc
proview
Commits
dfc95d5c
Commit
dfc95d5c
authored
Jun 07, 2019
by
Christoffer Ackelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
QT: Make the XttGe widget attempt to keep aspect ratio.
parent
b3029ac2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
1 deletion
+72
-1
xtt/lib/xtt/qt/xtt_ge_qt.cqt
xtt/lib/xtt/qt/xtt_ge_qt.cqt
+69
-0
xtt/lib/xtt/qt/xtt_ge_qt.h
xtt/lib/xtt/qt/xtt_ge_qt.h
+3
-1
No files found.
xtt/lib/xtt/qt/xtt_ge_qt.cqt
View file @
dfc95d5c
...
...
@@ -45,6 +45,7 @@
#include "xtt_xnav.h"
#include <QMenuBar>
#include <QResizeEvent>
#include <QVBoxLayout>
void XttGeQtWidget::focusInEvent(QFocusEvent* event)
...
...
@@ -229,6 +230,69 @@ void XttGeQtWidget::closeEvent(QCloseEvent* event)
QWidget::closeEvent(event);
}
void XttGeQtWidget::resizeEvent(QResizeEvent* event)
{
int oldWidth = event->oldSize().width();
int oldHeight = event->oldSize().height();
int width = event->size().width();
int height = event->size().height();
event->accept();
if (width != oldWidth && height != oldHeight) {
if (ge->min_aspect * height > width) {
int delta = height - width / ge->min_aspect;
if (height - delta >= 0) {
height -= delta;
} else {
delta = height * ge->min_aspect - width;
if (width + delta <= INT_MAX) {
width += delta;
}
}
}
if (ge->max_aspect * height < width) {
int delta = width - height * ge->max_aspect;
if (width - delta >= 0) {
width -= delta;
} else {
delta = width / ge->max_aspect - height;
if (height + delta <= INT_MAX) {
height += delta;
}
}
}
} else if (width != oldWidth) {
if (ge->min_aspect * height > width) {
int delta = height - width / ge->min_aspect;
if (height - delta >= 0) {
height -= delta;
}
}
if (ge->max_aspect * height < width) {
int delta = width / ge->max_aspect - height;
if (height + delta <= INT_MAX) {
height += delta;
}
}
} else if (height != oldHeight) {
if (ge->min_aspect * height > width) {
int delta = height * ge->min_aspect - width;
if (width + delta <= INT_MAX) {
width += delta;
}
}
if (ge->max_aspect * height < width) {
int delta = width - height * ge->max_aspect;
if (width - delta >= 0) {
width -= delta;
}
}
}
resize(width, height);
}
XttGeQt::XttGeQt(void* xg_parent_ctx, const char* xg_name,
const char* xg_filename, int xg_scrollbar, int xg_menu, int xg_navigator,
int xg_width, int xg_height, int x, int y, double scan_time,
...
...
@@ -378,6 +442,11 @@ XttGeQt::XttGeQt(void* xg_parent_ctx, const char* xg_name,
window_width = zoom * (x1 - x0);
window_height = zoom * (y1 - y0);
}
float rd = (window_width < 300 || window_height < 300) ? 0.2 : 0.05;
min_aspect = double(window_width) / window_height * (1.0 - rd);
max_aspect = double(window_width) / window_height * (1.0 + rd);
toplevel->setMinimumSize(window_width, window_height);
}
...
...
xtt/lib/xtt/qt/xtt_ge_qt.h
View file @
dfc95d5c
...
...
@@ -56,6 +56,7 @@ public:
QWidget
*
value_dialog
;
QMessageBox
*
confirm_widget
=
NULL
;
CoWowFocusTimerQt
focustimer
;
double
min_aspect
,
max_aspect
;
XttGeQt
(
void
*
parent_ctx
,
const
char
*
name
,
const
char
*
filename
,
int
scrollbar
,
int
menu
,
int
navigator
,
int
width
,
int
height
,
int
x
,
...
...
@@ -101,6 +102,7 @@ public:
protected:
void
focusInEvent
(
QFocusEvent
*
event
);
void
closeEvent
(
QCloseEvent
*
event
);
void
resizeEvent
(
QResizeEvent
*
event
);
public
slots
:
void
activate_confirm_ok
();
...
...
@@ -115,4 +117,4 @@ private:
XttGeQt
*
ge
;
};
#endif
\ No newline at end of file
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment