/** * 处理内容:窗体控件的创建 * @param void * @return void */ void MainWnd::createWidget() { // 创建标题栏 m_pTitleBar = new TitleBar(this); connect(m_pTitleBar,SIGNAL(menuClicked()),SLOT(showMenu())); connect(m_pTitleBar,SIGNAL(minClicked()),SLOT(showMin())); connect(m_pTitleBar,SIGNAL(maxClicked()),SLOT(showMax())); connect(m_pTitleBar,SIGNAL(closeClicked()),SLOT(showClose())); // 创建对工具栏 m_pToolBar = new ToolBar(this); // 创建内容区域 m_pContentWidget = new Html5Viewer(this); m_pContentWidget->setOrientation(Html5Viewer::ScreenOrientationAuto); //m_pContentWidget->showExpanded(); //m_pContentWidget->loadFile(QLatin1String("QtStyleSheetsReference.html")); QString strURL = SysSettings::Instance()->value(QString::fromLocal8Bit("url/turl"),QVariant()).toString(); m_pContentWidget->loadUrl(QUrl(strURL)); // 创建状态栏 m_pStatuBar = new StatusBar(this); // // 右键菜单 // connect(this,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(menuRight(const QPoint&))); }
// ================= // PRIVATE // ================= void LWindowFrame::InitWindow(){ anim = new QPropertyAnimation(this); //For simple window animations anim->setTargetObject(this); anim->setDuration(ANIMTIME); //In milliseconds connect(anim, SIGNAL(finished()), this, SLOT(finishedAnimation()) ); titleBar = new QLabel(this); //This is the "container" for all the title buttons/widgets titleBar->setObjectName("TitleBar"); titleBar->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); titleBar->setFocusPolicy(Qt::NoFocus); titleBar->setCursor(Qt::ArrowCursor); title = new QLabel(this); //Shows the window title/text title->setObjectName("Title"); title->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); title->setCursor(Qt::ArrowCursor); title->setFocusPolicy(Qt::NoFocus); icon = new QLabel(this); //Contains the window icon icon->setObjectName("Icon"); icon->setCursor(Qt::ArrowCursor); icon->setFocusPolicy(Qt::NoFocus); minB = new QToolButton(this); //Minimize Button minB->setObjectName("Minimize"); minB->setCursor(Qt::ArrowCursor); minB->setFocusPolicy(Qt::NoFocus); connect(minB, SIGNAL(clicked()), this, SLOT(minClicked()) ); maxB = new QToolButton(this); //Maximize Button maxB->setObjectName("Maximize"); maxB->setCursor(Qt::ArrowCursor); maxB->setFocusPolicy(Qt::NoFocus); connect(maxB, SIGNAL(clicked()), this, SLOT(maxClicked()) ); closeB = new QToolButton(this); closeB->setObjectName("Close"); closeB->setCursor(Qt::ArrowCursor); closeB->setFocusPolicy(Qt::NoFocus); connect(closeB, SIGNAL(clicked()), this, SLOT(closeClicked()) ); otherB = new QToolButton(this); //Button to place any other actions otherB->setObjectName("Options"); otherB->setCursor(Qt::ArrowCursor); otherB->setPopupMode(QToolButton::InstantPopup); otherB->setStyleSheet("QToolButton::menu-indicator{ image: none; }"); otherB->setFocusPolicy(Qt::NoFocus); otherM = new QMenu(this); //menu of "other" actions for the window otherB->setMenu(otherM); connect(otherM, SIGNAL(triggered(QAction*)), this, SLOT(otherClicked(QAction*)) ); //Now assemble the titlebar QHBoxLayout *HL = new QHBoxLayout(this); HL->setContentsMargins(0,0,0,0); HL->addWidget(otherB); HL->addWidget(icon); HL->addWidget(title); HL->addWidget(minB); HL->addWidget(maxB); HL->addWidget(closeB); titleBar->setLayout(HL); QVBoxLayout *VL = new QVBoxLayout(this); this->setLayout(VL); //The WinWidget container appears shifted right/down by 1 pixel for some reason // Adjust the margins to account for this variation VL->setContentsMargins(1,1,2,2); VL->setSpacing(0); //Have the window take the same initial size of the client window QRect geom = LWM::SYSTEM->WM_Window_Geom(CID); qDebug() << " - Load Size Hints" << "initial size:" << geom.size(); icccm_size_hints SH = LWM::SYSTEM->WM_ICCCM_GetNormalHints(CID); qDebug() << " - - Got Normal Hints"; if(!SH.isValid()){ SH = LWM::SYSTEM->WM_ICCCM_GetSizeHints(CID); } qDebug() << " - - Start resizing..."; if(SH.base_width>geom.width() && SH.base_height>geom.height()){ this->resize(SH.base_width, SH.base_height); } else if(SH.min_width>geom.width() && SH.min_height>geom.height()){ this->resize(SH.min_width, SH.min_height); } else if(SH.width>geom.width() && SH.height>geom.height()){ this->resize(SH.width, SH.height); } else if(geom.isNull()){ this->resize(100,80); } else{ this->resize( geom.size() ); } qDebug() << " - done"; //Now embed the native window into the frame WIN = QWindow::fromWinId(CID); WinWidget = QWidget::createWindowContainer( WIN, this); WinWidget->setCursor(Qt::ArrowCursor); //this is just a fallback - the window itself will adjust it //WINBACK = new QBackingStore(WIN); //create a data backup for the widget //Now assemble te initial layout for the window (all while still invisible) /*VL->addWidget(titleBar); VL->addWidget(WinWidget); VL->setStretch(1,1);*/ }