Commit afaf6a51 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

BUG #15506: Add border around active view.

Changed pqViewFrame to use a QFrame around the "central widget". We
set the border color for this frame to be either blue or same as
background. By using contents margin, we get the same effect as a 1
pixel white border inside the blue border.
parent a3edfa3c
......@@ -575,6 +575,7 @@ set (Module_UI_FILES
Resources/UI/pqSplineWidget.ui
Resources/UI/pqSpreadSheetViewDecorator.ui
Resources/UI/pqTimerLogDisplay.ui
Resources/UI/pqViewFrame.ui
Resources/UI/pqWriterDialog.ui
)
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>pqViewFrame</class>
<widget class="QWidget" name="pqViewFrame">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="TitleBar" native="true">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="TitleBarLayout">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="TitleLabel">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="CentralWidgetFrame">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<layout class="QVBoxLayout" name="CentralWidgetFrameLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -147,7 +147,6 @@ namespace
{
QWidget* viewWidget = pqview->widget();
frame->setCentralWidget(viewWidget);
viewWidget->setParent(frame);
}
}
......
/*=========================================================================
Program: ParaView
Module: $RCSfile$
Module: pqViewFrame.cxx
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
......@@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#include "pqViewFrame.h"
#include "ui_pqViewFrame.h"
#include "pqSetName.h"
......@@ -54,43 +55,42 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# include "unistd.h"
#endif
#define PEN_WIDTH 2
const int ICON_SIZE = 12;
class pqViewFrame::pqInternals
{
public:
Ui::pqViewFrame Ui;
pqInternals(pqViewFrame* self)
{
this->Ui.setupUi(self);
}
};
//-----------------------------------------------------------------------------
pqViewFrame::pqViewFrame(QWidget* parentObject)
: Superclass(parentObject),
DecorationsVisible(true),
TitleBarVisible(true),
BorderVisible(false),
BorderColor(QColor("blue")),
Buttons(SplitVertical | SplitHorizontal | Maximize | Close),
TitleBar(new QWidget(this)),
ToolBar (new QToolBar(this)),
TitleLabel(new QLabel(this)),
ContextMenu(new QMenu(this->TitleBar)),
UniqueID(QUuid::createUuid())
UniqueID(QUuid::createUuid()),
Internals(new pqViewFrame::pqInternals(this))
{
this->ToolBar->setIconSize(QSize (ICON_SIZE, ICON_SIZE));
QLayout* tbLayout = this->ToolBar->layout ();
tbLayout->setSpacing (0);
tbLayout->setContentsMargins (0, 0, 0, 0);
// to allow an empty frame to work with the focus stuff
this->setFocusPolicy(Qt::ClickFocus);
Ui::pqViewFrame& ui = this->Internals->Ui;
QVBoxLayout* vbox = new QVBoxLayout(this);
this->setLayout(vbox);
this->ToolBar = new QToolBar(this);
this->ToolBar->setObjectName("ToolBar");
this->ToolBar->setIconSize(QSize(ICON_SIZE, ICON_SIZE));
this->ToolBar->layout()->setSpacing(0);
this->ToolBar->layout()->setContentsMargins(0, 0, 0, 0);
this->TitleBar->setObjectName("TitleBar");
this->TitleBar->setAcceptDrops(true);
this->TitleBar->setContextMenuPolicy(Qt::CustomContextMenu);
QObject::connect(
this->TitleBar, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(contextMenuRequested(const QPoint&)));
this->connect(
ui.TitleBar, SIGNAL(customContextMenuRequested(const QPoint&)),
SLOT(contextMenuRequested(const QPoint&)));
// limits the titlebar's height.
this->TitleBar->installEventFilter(this);
// To handle drag/drop event.
ui.TitleBar->installEventFilter(this);
// Create standard buttons.
this->StandardToolButtons[SplitVertical] =
......@@ -114,9 +114,14 @@ pqViewFrame::pqViewFrame(QWidget* parentObject)
QIcon(this->style()->standardPixmap(QStyle::SP_TitleBarCloseButton)),
"Close", this) << pqSetName("Close"));
this->updateTitleBar();
this->updateLayout();
// Setup the title bar.
ui.TitleBarLayout->insertWidget(0, this->ToolBar);
foreach (QToolButton* button, this->StandardToolButtons)
{
ui.TitleBarLayout->addWidget(button);
}
this->ContextMenu = new QMenu(ui.TitleBar),
this->ContextMenu->setObjectName("FrameContextMenu");
this->ContextMenu->addAction(
this->StandardToolButtons[SplitHorizontal]->defaultAction());
......@@ -124,19 +129,38 @@ pqViewFrame::pqViewFrame(QWidget* parentObject)
this->StandardToolButtons[SplitVertical]->defaultAction());
this->ContextMenu->addAction(
this->StandardToolButtons[Close]->defaultAction());
this->setBorderColor(QColor("blue"));
}
//-----------------------------------------------------------------------------
pqViewFrame::~pqViewFrame()
{
delete this->TitleBar;
}
//-----------------------------------------------------------------------------
void pqViewFrame::setBorderColor(const QColor& clr)
{
if (this->BorderColor != clr)
{
this->BorderColor = clr;
this->updateComponentVisibilities();
}
}
//-----------------------------------------------------------------------------
void pqViewFrame::setCentralWidget(QWidget* widget)
{
this->CentralWidget = widget;
this->updateLayout();
Ui::pqViewFrame& ui = this->Internals->Ui;
while (QLayoutItem* item = ui.CentralWidgetFrameLayout->takeAt(0))
{
delete item;
}
if (this->CentralWidget)
{
ui.CentralWidgetFrameLayout->addWidget(this->CentralWidget);
}
}
//-----------------------------------------------------------------------------
......@@ -148,132 +172,49 @@ QWidget* pqViewFrame::centralWidget() const
//-----------------------------------------------------------------------------
void pqViewFrame::setTitle(const QString& text)
{
this->TitleLabel->setText(text);
this->PlainTitle = text;
this->updateComponentVisibilities();
}
//-----------------------------------------------------------------------------
QString pqViewFrame::title() const
{
return this->TitleLabel->text();
return this->Internals->Ui.TitleLabel->text();
}
//-----------------------------------------------------------------------------
void pqViewFrame::updateLayout()
void pqViewFrame::updateComponentVisibilities()
{
QVBoxLayout* vbox = new QVBoxLayout();
if ((!this->TitleBarVisible && !this->BorderVisible) ||
!this->DecorationsVisible)
{
vbox->setMargin(0);
vbox->setSpacing(0);
}
else
{
vbox->setMargin(PEN_WIDTH);
vbox->setSpacing(PEN_WIDTH);
}
bool showTitleBar = this->DecorationsVisible && this->TitleBarVisible;
bool showBorder = this->DecorationsVisible && this->BorderVisible;
if (this->TitleBarVisible && this->DecorationsVisible)
Ui::pqViewFrame& ui = this->Internals->Ui;
ui.TitleBar->setVisible(showTitleBar);
if (showBorder)
{
vbox->addWidget(this->TitleBar);
}
if (this->CentralWidget)
{
vbox->addWidget(this->CentralWidget);
ui.CentralWidgetFrame->setForegroundRole(QPalette::WindowText);
ui.CentralWidgetFrame->setStyleSheet(
QString("QFrame#CentralWidgetFrame { color: rgb(%1, %2, %3); }")
.arg(this->BorderColor.red())
.arg(this->BorderColor.green())
.arg(this->BorderColor.blue()));
ui.TitleLabel->setText(QString("<b><u>%1</u></b>").arg(this->PlainTitle));
}
else
{
vbox->addStretch();
}
delete this->layout();
this->setLayout(vbox);
// ensure that the frame is repainted.
this->update();
}
//-----------------------------------------------------------------------------
void pqViewFrame::updateTitleBar()
{
QHBoxLayout* hbox = new QHBoxLayout();
hbox->setMargin(0);
hbox->setSpacing(0);
hbox->addWidget (this->ToolBar);
hbox->addStretch();
this->TitleLabel->setAlignment(Qt::AlignRight);
this->TitleLabel->setIndent(10);
hbox->addWidget(this->TitleLabel);
foreach (QToolButton* button, this->StandardToolButtons)
{
button->hide();
}
if (this->standardButtons() & SplitHorizontal)
{
QToolButton* button = this->StandardToolButtons[SplitHorizontal];
hbox->addWidget(button);
button->show();
ui.CentralWidgetFrame->setForegroundRole(QPalette::Window);
ui.CentralWidgetFrame->setStyleSheet(QString());
ui.TitleLabel->setText(this->PlainTitle);
}
if (this->standardButtons() & SplitVertical)
if (this->DecorationsVisible)
{
QToolButton* button = this->StandardToolButtons[SplitVertical];
hbox->addWidget(button);
button->show();
ui.CentralWidgetFrame->setFrameStyle(QFrame::Plain|QFrame::Box);
ui.CentralWidgetFrameLayout->setContentsMargins(1, 1, 1, 1);
}
if (this->standardButtons() & Maximize)
{
QToolButton* button = this->StandardToolButtons[Maximize];
hbox->addWidget(button);
button->show();
}
if (this->standardButtons() & Restore)
{
QToolButton* button = this->StandardToolButtons[Restore];
hbox->addWidget(button);
button->show();
}
if (this->standardButtons() & Close)
{
QToolButton* button = this->StandardToolButtons[Close];
hbox->addWidget(button);
button->show();
}
delete this->TitleBar->layout();
this->TitleBar->setLayout(hbox);
}
//-----------------------------------------------------------------------------
void pqViewFrame::paintEvent(QPaintEvent* evt)
{
this->Superclass::paintEvent(evt);
if (this->BorderVisible && this->DecorationsVisible)
else
{
QPainter painter(this);
QPen pen;
pen.setColor(this->BorderColor);
pen.setWidth(PEN_WIDTH);
painter.setPen(pen);
QRect borderRect = this->contentsRect();
if (this->isTitleBarVisible())
{
QLayoutItem* titlebar = this->layout()->itemAt(0);
borderRect.adjust(-PEN_WIDTH/2+2,
titlebar->geometry().height()+4-PEN_WIDTH/2,
PEN_WIDTH/2-2,
PEN_WIDTH/2-2);
}
else
{
borderRect.adjust(
-PEN_WIDTH/2+2, PEN_WIDTH/2, PEN_WIDTH/2-2, PEN_WIDTH/2-2);
}
painter.drawRect(borderRect);
ui.CentralWidgetFrame->setFrameStyle(QFrame::NoFrame);
ui.CentralWidgetFrameLayout->setContentsMargins(0, 0, 0, 0);
}
}
......@@ -283,7 +224,11 @@ void pqViewFrame::setStandardButtons(StandardButtons buttons)
if (this->Buttons != buttons)
{
this->Buttons = buttons;
this->updateTitleBar();
for (StandardToolButtonsMap::iterator iter = this->StandardToolButtons.begin();
iter != this->StandardToolButtons.end(); ++iter)
{
iter.value()->setVisible(this->Buttons & iter.key());
}
}
}
......@@ -319,7 +264,6 @@ void pqViewFrame::buttonClicked()
void pqViewFrame::addTitleBarAction(QAction* action)
{
this->ToolBar->addAction (action);
this->updateTitleBar();
}
//-----------------------------------------------------------------------------
......@@ -350,14 +294,16 @@ void pqViewFrame::removeTitleBarActions()
void pqViewFrame::contextMenuRequested(const QPoint& point)
{
this->setFocus(Qt::OtherFocusReason);
this->ContextMenu->exec(this->TitleBar->mapToGlobal(point));
Ui::pqViewFrame& ui = this->Internals->Ui;
this->ContextMenu->exec(ui.TitleBar->mapToGlobal(point));
}
//-----------------------------------------------------------------------------
bool pqViewFrame::eventFilter(QObject* caller, QEvent* evt)
{
if (evt->type() == QEvent::MouseButtonPress)
{
{
QMouseEvent *mouseEvent=(QMouseEvent*)evt;
if (mouseEvent->button() == Qt::LeftButton)
{
......@@ -462,3 +408,9 @@ void pqViewFrame::drop(QDropEvent* evt)
evt->ignore();
}
}
//-----------------------------------------------------------------------------
QMenu* pqViewFrame::contextMenu() const
{
return this->ContextMenu;
}
......@@ -37,10 +37,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QPointer>
#include <QMap>
#include <QUuid>
#include <QScopedPointer>
class QDragEnterEvent;
class QDragMoveEvent;
class QDropEvent;
class QFrame;
class QLabel;
class QMenu;
class QToolBar;
......@@ -63,13 +65,16 @@ public:
void setTitle(const QString& text);
QString title() const;
/// Get/Set the central widget shown in this frame.
/// Get/Set the central widget shown in this frame. Similar to
/// QLayout::addWidget, this call takes the ownership of the widget and the
/// widget will be deleted with pqViewFrame is deleted or another widget is set
/// using setCentralWidget().
void setCentralWidget(QWidget* widget);
QWidget* centralWidget() const;
/// Get/Set the border BorderColor. The border is only drawn when the
/// borderVisibility is set to true.
void setBorderColor(const QColor& clr) { this->BorderColor = clr; }
void setBorderColor(const QColor& clr);
const QColor& borderColor() const { return this->BorderColor; }
/// Get/Set the border visibility.
......@@ -81,8 +86,8 @@ public:
enum StandardButton
{
NoButton =0x0000,
SplitVertical =0x0001,
SplitHorizontal =0x0002,
SplitHorizontal =0x0001,
SplitVertical =0x0002,
Maximize =0x0004,
Restore =0x0008,
Close =0x0010
......@@ -104,8 +109,7 @@ public:
void removeTitleBarActions();
/// Provides access to the context menu.
QMenu* contextMenu() const
{ return this->ContextMenu; }
QMenu* contextMenu() const;
/// provides access to the unique id assigned to the frame.
QUuid uniqueID() const
......@@ -120,36 +124,35 @@ signals:
/// Fired to indicate the positions for the two frames need to be swapped.
void swapPositions(const QString& other);
public slots:
/// set whether the border is visible.
void setBorderVisibility(bool val)
void setBorderVisibility(bool val)
{
this->BorderVisible = val;
this->updateLayout();
this->updateComponentVisibilities();
}
/// set whether the title-bar is visible.
void setTitleBarVisibility(bool val)
{
this->TitleBarVisible = val;
this->updateLayout();
this->updateComponentVisibilities();
}
void setDecorationsVisibility(bool val)
{
this->DecorationsVisible = val;
this->updateLayout();
this->updateComponentVisibilities();
}
/// event filter to handle drag/drop events.
virtual bool eventFilter(QObject*, QEvent*);
protected:
/// updates the layout.
void updateLayout();
void updateTitleBar();
void paintEvent(QPaintEvent* event);
/// Updates the visibilities for various components of the pqViewFrame based
/// on flags set on the instance.
virtual void updateComponentVisibilities();
/// methods to manage drag-drop.
void drag();
......@@ -167,20 +170,25 @@ protected:
bool BorderVisible;
QColor BorderColor;
StandardButtons Buttons;
QPointer<QWidget> CentralWidget;
QPointer<QWidget> TitleBar;
QPointer<QToolBar> ToolBar;
QPointer<QLabel> TitleLabel;
QMenu* ContextMenu;
QPointer<QWidget> CentralWidget;
QPointer<QMenu> ContextMenu;
QUuid UniqueID;
QPoint DragStartPosition;
QMap<StandardButton, QPointer<QToolButton> > StandardToolButtons;
typedef QMap<StandardButton, QPointer<QToolButton> > StandardToolButtonsMap;
StandardToolButtonsMap StandardToolButtons;
QPalette PaletteWithBorder;
QPalette PaletteWithoutBorder;
QString PlainTitle;
private:
Q_DISABLE_COPY(pqViewFrame)
/// creates a tool button for the action.
QToolButton* createButton(QAction* action);