1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
#if defined(Hiro_Window)
namespace hiro {
auto pWindow::construct() -> void {
qtWindow = new QtWindow(*this);
qtWindow->setWindowTitle(" ");
//if program was given a name, try and set the window taskbar icon to a matching pixmap image
if(auto name = Application::state.name) {
if(file::exists({userpath(), ".local/share/icons/", name, ".png"})) {
qtWindow->setWindowIcon(QIcon(QString::fromUtf8(string{userpath(), ".local/share/icons/", name, ".png"})));
} else if(file::exists({"/usr/local/share/pixmaps/", name, ".png"})) {
qtWindow->setWindowIcon(QIcon(QString::fromUtf8(string{"/usr/local/share/pixmaps/", name, ".png"})));
} else if(file::exists({"/usr/share/pixmaps/", name, ".png"})) {
qtWindow->setWindowIcon(QIcon(QString::fromUtf8(string{"/usr/share/pixmaps/", name, ".png"})));
}
}
qtLayout = new QVBoxLayout(qtWindow);
qtLayout->setMargin(0);
qtLayout->setSpacing(0);
qtWindow->setLayout(qtLayout);
qtMenuBar = new QMenuBar(qtWindow);
qtMenuBar->setVisible(false);
qtLayout->addWidget(qtMenuBar);
qtContainer = new QWidget(qtWindow);
qtContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
qtContainer->setVisible(true);
qtLayout->addWidget(qtContainer);
qtStatusBar = new QStatusBar(qtWindow);
qtStatusBar->setSizeGripEnabled(true);
qtStatusBar->setVisible(false);
qtLayout->addWidget(qtStatusBar);
setBackgroundColor(state().backgroundColor);
setDroppable(state().droppable);
setGeometry(state().geometry);
setResizable(state().resizable);
setTitle(state().title);
}
auto pWindow::destruct() -> void {
delete qtStatusBar;
delete qtContainer;
delete qtMenuBar;
delete qtLayout;
delete qtWindow;
}
auto pWindow::append(sLayout layout) -> void {
}
auto pWindow::append(sMenuBar menuBar) -> void {
}
auto pWindow::append(sStatusBar statusBar) -> void {
}
auto pWindow::focused() const -> bool {
return qtWindow->isActiveWindow() && !qtWindow->isMinimized();
}
auto pWindow::frameMargin() const -> Geometry {
if(state().fullScreen) return {
0, _menuHeight(),
0, _menuHeight() + _statusHeight()
};
return {
settings->geometry.frameX,
settings->geometry.frameY + _menuHeight(),
settings->geometry.frameWidth,
settings->geometry.frameHeight + _menuHeight() + _statusHeight()
};
}
auto pWindow::remove(sLayout layout) -> void {
}
auto pWindow::remove(sMenuBar menuBar) -> void {
//QMenuBar::removeMenu() does not exist
//qtMenu->clear();
//for(auto& menu : window.state.menu) append(menu);
}
auto pWindow::remove(sStatusBar statusBar) -> void {
}
auto pWindow::setBackgroundColor(Color color) -> void {
if(color) {
QPalette palette;
palette.setColor(QPalette::Background, QColor(color.red(), color.green(), color.blue() /*, color.alpha() */));
qtContainer->setPalette(palette);
qtContainer->setAutoFillBackground(true);
//translucency results are very unpleasant without a compositor; so disable for now
//qtWindow->setAttribute(Qt::WA_TranslucentBackground, color.alpha() != 255);
}
}
auto pWindow::setDroppable(bool droppable) -> void {
qtWindow->setAcceptDrops(droppable);
}
auto pWindow::setEnabled(bool enabled) -> void {
}
auto pWindow::setFocused() -> void {
qtWindow->raise();
qtWindow->activateWindow();
}
auto pWindow::setFullScreen(bool fullScreen) -> void {
lock();
if(fullScreen) {
windowedGeometry = state().geometry;
qtLayout->setSizeConstraint(QLayout::SetDefaultConstraint);
qtContainer->setFixedSize(Desktop::size().width() - frameMargin().width(), Desktop::size().height() - frameMargin().height());
qtWindow->showFullScreen();
state().geometry = Monitor::geometry(Monitor::primary());
} else {
setResizable(state().resizable);
qtWindow->showNormal();
qtWindow->adjustSize();
self().setGeometry(windowedGeometry);
}
unlock();
}
auto pWindow::setGeometry(Geometry geometry) -> void {
lock();
Application::processEvents();
QApplication::syncX();
setResizable(state().resizable);
qtWindow->move(geometry.x() - frameMargin().x(), geometry.y() - frameMargin().y());
//qtWindow->adjustSize() fails if larger than 2/3rds screen size
qtWindow->resize(qtWindow->sizeHint());
if(state().resizable) {
//required to allow shrinking window from default size
qtWindow->setMinimumSize(1, 1);
qtContainer->setMinimumSize(1, 1);
}
// for(auto& layout : window.state.layout) {
// geometry.x = geometry.y = 0;
// layout.setGeometry(geometry);
// }
unlock();
}
auto pWindow::setModal(bool modal) -> void {
if(modal) {
//windowModality can only be enabled while window is invisible
setVisible(false);
qtWindow->setWindowModality(Qt::ApplicationModal);
setVisible(true);
while(!Application::state.quit && state().modal) {
if(Application::state.onMain) {
Application::doMain();
} else {
usleep(20 * 1000);
}
Application::processEvents();
}
qtWindow->setWindowModality(Qt::NonModal);
}
}
auto pWindow::setResizable(bool resizable) -> void {
if(resizable) {
qtLayout->setSizeConstraint(QLayout::SetDefaultConstraint);
qtContainer->setMinimumSize(state().geometry.width(), state().geometry.height());
} else {
qtLayout->setSizeConstraint(QLayout::SetFixedSize);
qtContainer->setFixedSize(state().geometry.width(), state().geometry.height());
}
qtStatusBar->setSizeGripEnabled(resizable);
}
auto pWindow::setTitle(const string& text) -> void {
qtWindow->setWindowTitle(QString::fromUtf8(text));
}
auto pWindow::setVisible(bool visible) -> void {
lock();
qtWindow->setVisible(visible);
if(visible) {
_updateFrameGeometry();
setGeometry(state().geometry);
}
unlock();
}
/*
if(widget.font().empty() && !window.state.widgetFont.empty()) {
widget.setFont(window.state.widgetFont);
}
if(widget.font().empty()) widget.p.setFont(Font::sans(8));
if(GetParentWidget(&widget)) {
widget.p.qtWidget->setParent(GetParentWidget(&widget)->p.container(widget));
} else {
widget.p.qtWidget->setParent(qtContainer);
}
widget.setVisible(widget.visible());
}
*/
auto pWindow::_append(mWidget& widget) -> void {
if(auto self = widget.self()) {
self->qtWidget->setParent(qtContainer);
}
}
auto pWindow::_menuHeight() const -> signed {
return qtMenuBar->isVisible() ? settings->geometry.menuHeight : 0;
}
auto pWindow::_statusHeight() const -> signed {
return qtStatusBar->isVisible() ? settings->geometry.statusHeight : 0;
}
auto pWindow::_updateFrameGeometry() -> void {
pApplication::syncX();
QRect border = qtWindow->frameGeometry();
QRect client = qtWindow->geometry();
settings->geometry.frameX = client.x() - border.x();
settings->geometry.frameY = client.y() - border.y();
settings->geometry.frameWidth = border.width() - client.width();
settings->geometry.frameHeight = border.height() - client.height();
if(qtMenuBar->isVisible()) {
pApplication::syncX();
settings->geometry.menuHeight = qtMenuBar->height();
}
if(qtStatusBar->isVisible()) {
pApplication::syncX();
settings->geometry.statusHeight = qtStatusBar->height();
}
settings->save();
}
auto QtWindow::closeEvent(QCloseEvent* event) -> void {
event->ignore();
if(p.state().onClose) p.self().doClose();
else p.self().setVisible(false);
if(p.state().modal && !p.self().visible()) p.self().setModal(false);
}
auto QtWindow::moveEvent(QMoveEvent* event) -> void {
if(!p.locked() && !p.state().fullScreen && p.qtWindow->isVisible()) {
p.state().geometry.setPosition({
p.state().geometry.x() + event->pos().x() - event->oldPos().x(),
p.state().geometry.y() + event->pos().y() - event->oldPos().y()
});
}
if(!p.locked()) {
p.self().doMove();
}
}
auto QtWindow::dragEnterEvent(QDragEnterEvent* event) -> void {
if(event->mimeData()->hasUrls()) {
event->acceptProposedAction();
}
}
auto QtWindow::dropEvent(QDropEvent* event) -> void {
if(auto paths = DropPaths(event)) p.self().doDrop(paths);
}
auto QtWindow::keyPressEvent(QKeyEvent* event) -> void {
// Keyboard::Keycode sym = Keysym(event->nativeVirtualKey());
// if(sym != Keyboard::Keycode::None && self.window.onKeyPress) self.window.onKeyPress(sym);
}
auto QtWindow::keyReleaseEvent(QKeyEvent* event) -> void {
// Keyboard::Keycode sym = Keysym(event->nativeVirtualKey());
// if(sym != Keyboard::Keycode::None && self.window.onKeyRelease) self.window.onKeyRelease(sym);
}
auto QtWindow::resizeEvent(QResizeEvent*) -> void {
if(!p.locked() && !p.state().fullScreen && p.qtWindow->isVisible()) {
p.state().geometry.setSize({
p.qtContainer->geometry().width(),
p.qtContainer->geometry().height()
});
}
if(auto& layout = p.state().layout) {
layout->setGeometry(p.self().geometry().setPosition(0, 0));
}
if(!p.locked()) {
p.self().doSize();
}
}
auto QtWindow::sizeHint() const -> QSize {
unsigned width = p.state().geometry.width();
unsigned height = p.state().geometry.height();
if(p.qtMenuBar->isVisible()) height += settings->geometry.menuHeight;
if(p.qtStatusBar->isVisible()) height += settings->geometry.statusHeight;
return QSize(width, height);
}
}
#endif
|