void TPanelTitleBar::paintEvent(QPaintEvent *) { QPainter painter(this); QRect rect = this->rect(); QColor titleColor; QColor brushColor; TPanel *dw = qobject_cast<TPanel *>(parentWidget()); Q_ASSERT(dw != 0); if (!dw->isFloating()) { if (dw->widgetInThisPanelIsFocused()) { brushColor = QColor(64, 64, 64); titleColor = QColor(Qt::white); } else { brushColor = QColor(100, 100, 100); titleColor = QColor(192, 192, 192); } } else if (isActiveWindow()) { brushColor = QColor(96, 96, 96); titleColor = QColor(Qt::white); } else { brushColor = QColor(128, 128, 128); titleColor = QColor(192, 192, 192); } painter.setBrush(brushColor); painter.setPen(Qt::black); painter.drawRect(rect.adjusted(0, 0, -1, -1)); painter.setPen(titleColor); painter.drawLine(rect.topLeft(), rect.bottomLeft()); painter.drawLine(rect.topLeft(), rect.topRight()); if (dw->getOrientation() == TDockWidget::vertical) { QString titleText = painter.fontMetrics().elidedText( dw->windowTitle(), Qt::ElideRight, rect.width() - 50); painter.setBrush(Qt::NoBrush); painter.setPen(titleColor); painter.drawText(QPointF(10, 15), titleText); } if (dw->isFloating()) { const static QPixmap closeButtonPixmap(":/Resources/close_pane.png"); const static QPixmap closeButtonPixmapOver(":/Resources/close_pane_rollover.png"); QRect closeRect(rect.right() - 17, rect.top() + 1, 16, 16); if (m_closeButtonHighlighted) painter.drawPixmap(closeRect, closeButtonPixmapOver); else painter.drawPixmap(closeRect, closeButtonPixmap); } painter.end(); }
void TPanelTitleBar::paintEvent(QPaintEvent *) { QPainter painter(this); QRect rect = this->rect(); bool isPanelActive; TPanel *dw = qobject_cast<TPanel *>(parentWidget()); Q_ASSERT(dw != 0); // docked panel if (!dw->isFloating()) { isPanelActive = dw->widgetInThisPanelIsFocused(); qDrawBorderPixmap(&painter, rect, QMargins(3, 3, 3, 3), (isPanelActive) ? m_activeBorderPm : m_borderPm); } // floating panel else { isPanelActive = isActiveWindow(); qDrawBorderPixmap( &painter, rect, QMargins(3, 3, 3, 3), (isPanelActive) ? m_floatActiveBorderPm : m_floatBorderPm); } if (dw->getOrientation() == TDockWidget::vertical) { QString titleText = painter.fontMetrics().elidedText( dw->windowTitle(), Qt::ElideRight, rect.width() - 50); painter.setBrush(Qt::NoBrush); painter.setPen(isPanelActive ? m_activeTitleColor : m_titleColor); painter.drawText(QPointF(10, 15), titleText); } if (dw->isFloating()) { const static QPixmap closeButtonPixmap( svgToPixmap(":/Resources/pane_close.svg", QSize(18, 18))); const static QPixmap closeButtonPixmapOver( svgToPixmap(":/Resources/pane_close_rollover.svg", QSize(18, 18))); QPoint closeButtonPos(rect.right() - 18, rect.top() + 1); if (m_closeButtonHighlighted) painter.drawPixmap(closeButtonPos, closeButtonPixmapOver); else painter.drawPixmap(closeButtonPos, closeButtonPixmap); } painter.end(); }
TPanel *OpenFloatingPanel::getOrOpenFloatingPanel( const std::string &panelType) { TMainWindow *currentRoom = TApp::instance()->getCurrentRoom(); QList<TPanel *> list = currentRoom->findChildren<TPanel *>(); QPoint lastFloatingPos = QPoint(0, 0); for (int i = 0; i < list.size(); i++) { TPanel *panel = list.at(i); // we want floating panel (possibly hidden) with the correct name if (panel->getPanelType() == panelType && panel->isFloating()) { // if there is already a floating panel and MultipleInstances are // not allowed we must use it if (!panel->areMultipleInstancesAllowed() && !panel->isHidden()) { activateWidget(panel); return panel; } // If there is a hidden panel we can show and use it if (panel->isHidden()) { // Alcuni pannelli devono essere resettati (Es.: il paletteViewerPanel) panel->reset(); // Devo porre il pannello sotto il controllo del layout della stanza currentRoom->addDockWidget(panel); panel->show(); panel->raise(); return panel; } else lastFloatingPos = panel->pos(); } } // No panel found. We must create a new pane TPanel *panel = TPanelFactory::createPanel(currentRoom, QString::fromStdString(panelType)); if (!panel) return 0; // it should never happen // panel->setWindowTitle(QObject::tr(m_title.toStdString().c_str())); panel->setFloating(true); panel->show(); panel->raise(); if (!lastFloatingPos.isNull()) panel->move(QPoint(lastFloatingPos.x() + 30, lastFloatingPos.y() + 30)); return panel; }