aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core/libLumina/RootSubWindow.cpp
blob: f1d5fe6151e0a7dd2ac9ae9bf75d50449a9ccb43 (plain)
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
//===========================================
//  Lumina Desktop source code
//  Copyright (c) 2017, Ken Moore
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#include "RootSubWindow.h"
#include <QDebug>

// === PUBLIC ===
RootSubWindow::RootSubWindow(QMdiArea *root, WId window, Qt::WindowFlags flags) : \
	QMdiSubWindow(0, flags){
  this->setAttribute(Qt::WA_DeleteOnClose);
  //Create the QWindow and QWidget containers for the window
  closing = false;
  CID = window;
  WIN = QWindow::fromWinId(CID);
  WinWidget = QWidget::createWindowContainer( WIN, this);
  this->setWidget(WinWidget);
  //Hookup the signals/slots
  connect(this, SIGNAL(aboutToActivate()), this, SLOT(aboutToActivate()) );
  connect(WIN, SIGNAL(windowTitleChanged(const QString&)), this, SLOT(setWindowTitle(const QString&)) );
  connect(WIN, SIGNAL(heightChanged(int)), this, SLOT(adjustHeight(int) ));  
  connect(WIN, SIGNAL(widthChanged(int)), this, SLOT(adjustWidth(int) ));

  qDebug() << "Initial Window Geometry:" << WIN->geometry();
  qDebug() << "Initial Widget Geometry:" << WinWidget->geometry();
  qDebug() << "Minimums:";
  qDebug() << " - Height:" << WIN->minimumHeight();
  qDebug() << " - Width:" << WIN->minimumWidth();

  //this->resize(WinWidget->size());
  //Now add this window to the root QMdiArea
  root->addSubWindow(this); 
}

RootSubWindow::~RootSubWindow(){

}

WId RootSubWindow::id(){
  return CID;
}

// === PRIVATE ===

// === PUBLIC SLOTS ===
void RootSubWindow::clientClosed(){
  qDebug() << "Client Closed";
  closing = true;
  this->close();
}

void RootSubWindow::clientHidden(){
  qDebug() << "Client Hidden";
  this->hide();
}

void RootSubWindow::clientShown(){
  qDebug() << "Client Shown";
  this->show();
}

// === PRIVATE SLOTS ===
void RootSubWindow::aboutToActivate(){
  emit Activated(CID); //need to activate the subwindow - not the frame
  WIN->requestActivate();
}

void RootSubWindow::adjustHeight(int val){
  qDebug() << "Adjust height:" << val;
  WinWidget->resize(WinWidget->width(), val);
}

void RootSubWindow::adjustWidth(int val){
  qDebug() << "Adjust Width:" << val;
  WinWidget->resize(val, WinWidget->height());
}

// === PROTECTED ===
void RootSubWindow::closeEvent(QCloseEvent *ev){
  if(!closing){
    qDebug() << "Close Window By Button:" << CID;
    ev->ignore();
    WIN->destroy();
  }else{
    QMdiSubWindow::closeEvent(ev);
  }
  
}
bgstack15