Updates default stylesheet and demo app

This commit is contained in:
mfreiholz 2016-03-08 14:24:33 +01:00
parent 9bbc5e41a3
commit 34cf851e24
14 changed files with 195 additions and 89 deletions

View File

@ -22,7 +22,7 @@ class InternalContentData;
/*!
* ContainerWidget is the main container to provide the docking
* functionality. It manages mulitple Sections and all possible areas.
* functionality. It manages multiple sections with all possible areas.
*/
class ADS_EXPORT_API ContainerWidget : public QFrame
{
@ -130,7 +130,7 @@ signals:
/*!
* Emits whenever the "isActiveTab" state of a SectionContent changes.
* Whenever the users sets another tab as active, this signal gets invoked
* for the old now inactive tab and the new active tab (the order is unspecified).
* for the old tab and the new active tab (the order is unspecified).
*/
void activeTabChanged(const SectionContent::RefPtr& sc, bool active);

View File

@ -14,5 +14,6 @@
<file>img/splitter-vertical.png</file>
<file>stylesheets/default-windows.css</file>
<file>stylesheets/vendor-partsolutions.css</file>
<file>stylesheets/modern-windows.css</file>
</qresource>
</RCC>

View File

@ -3,28 +3,69 @@
* Note: Always use CSS-classes with and without "ads--" namespace to support Qt4 & Qt5
*/
QSplitter::handle {
ads--ContainerWidget,
ContainerWidget
{
background: palette(dark);
}
ads--ContainerWidget, ContainerWidget {
ads--ContainerWidget QSplitter::handle,
ContainerWidget QSplitter::handle
{
background: palette(dark);
}
ads--SectionWidget, SectionWidget {
ads--SectionWidget,
SectionWidget
{
background: palette(window);
}
ads--SectionTitleWidget, SectionTitleWidget {
background: palette(window);
border-right: 1px solid palette(light);
padding: 9px;
}
ads--SectionTitleWidget[activeTab="true"], SectionTitleWidget[activeTab="true"] {
background: palette(light);
}
ads--SectionContentWidget, SectionContentWidget {
border: 1px solid palette(light);
}
ads--SectionTitleWidget,
SectionTitleWidget
{
background: palette(window);
border-color: palette(light);
border-style: solid;
border-width: 0 1px 0 0;
padding: 0 9px;
}
ads--SectionTitleWidget[activeTab="true"],
SectionTitleWidget[activeTab="true"]
{
/* background: palette(light);*/
/* background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(255, 255, 255, 255), stop:1 rgba(240, 240, 240, 255));*/
background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:0.5, stop:0 palette(window), stop:1 palette(light));
}
ads--SectionContentWidget,
SectionContentWidget
{
background: palette(light);
border-color: palette(light);
border-style: solid;
border-width: 1px 0 0 0;
}
/* Special: QLabels inside SectionTitleWidget
*/
ads--SectionTitleWidget QLabel,
SectionTitleWidget QLabel
{
color: palette(dark);
}
ads--SectionTitleWidget[activeTab="true"] QLabel,
SectionTitleWidget[activeTab="true"] QLabel
{
color: palette(foreground);
}
/* Special: QLabels inside SectionTitleWidget, which is floating
*/
ads--FloatingWidget ads--SectionTitleWidget QLabel,
FloatingWidget SectionTitleWidget QLabel
{
color: palette(foreground);
}

View File

@ -0,0 +1,35 @@
QSplitter::handle {
background: palette(light);
}
ads--ContainerWidget, ContainerWidget {
background: palette(light);
}
ads--SectionWidget, SectionWidget {
background: palette(light);
}
ads--SectionTitleWidget, SectionTitleWidget {
background: #ffffff;
}
ads--SectionTitleWidget QLabel, SectionTitleWidget QLabel {
color: #000000;
}
ads--SectionTitleWidget[activeTab="true"], SectionTitleWidget[activeTab="true"] {
background: #000000;
border-right: 1px solid #000000;
padding: 9px;
}
ads--SectionTitleWidget[activeTab="true"] QLabel, SectionTitleWidget[activeTab="true"] QLabel {
color: #ffffff;
}
ads--SectionContentWidget, SectionContentWidget {
border: 1px solid #000000;
}
QAbstractItemView {
border: 0;
}

View File

@ -14,13 +14,41 @@ IconTitleWidget::IconTitleWidget(const QIcon& icon, const QString& title, QWidge
setLayout(l);
_iconLabel = new QLabel();
if (!icon.isNull())
_iconLabel->setPixmap(icon.pixmap(16, 16));
l->addWidget(_iconLabel);
_titleLabel = new QLabel();
_titleLabel->setText(title);
l->addWidget(_titleLabel, 1);
setIcon(icon);
setTitle(title);
}
void IconTitleWidget::setIcon(const QIcon& icon)
{
if (icon.isNull())
{
_iconLabel->setPixmap(QPixmap());
_iconLabel->setVisible(false);
}
else
{
_iconLabel->setPixmap(icon.pixmap(16, 16));
_iconLabel->setVisible(true);
}
}
void IconTitleWidget::setTitle(const QString& title)
{
if (title.isEmpty())
{
_titleLabel->setText(QString());
_titleLabel->setVisible(false);
}
else
{
_titleLabel->setText(title);
_titleLabel->setVisible(true);
}
}
void IconTitleWidget::polishUpdate()

View File

@ -12,6 +12,10 @@ class IconTitleWidget : public QFrame
public:
explicit IconTitleWidget(const QIcon& icon, const QString& title, QWidget *parent = 0);
public slots:
void setIcon(const QIcon& icon);
void setTitle(const QString& title);
void polishUpdate();
public:

View File

@ -4,59 +4,27 @@
#include "mainwindow.h"
int main(int argc, char *argv[])
static void initStyleSheet(QApplication& a)
{
QApplication a(argc, argv);
a.setQuitOnLastWindowClosed(true);
//Q_INIT_RESOURCE(ads);
// Load style sheet
// QFile f(":/stylesheets/default-windows.css");
QFile f(":/stylesheets/vendor-partsolutions.css");
QFile f(":/stylesheets/default-windows.css");
// QFile f(":/stylesheets/modern-windows.css");
// QFile f(":/stylesheets/vendor-partsolutions.css");
if (f.open(QFile::ReadOnly))
{
QByteArray ba = f.readAll();
f.close();
a.setStyleSheet(QString(ba));
}
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//Q_INIT_RESOURCE(ads);
a.setQuitOnLastWindowClosed(true);
initStyleSheet(a);
MainWindow mw;
mw.show();
return a.exec();
}
// a.setStyleSheet(""
// " QSplitter::handle { border: 1px solid #000000; background: #000000; } "
// " ads--ContainerWidget { border: 1px solid #ff0000; background: #FFE6E6; padding: 6px; } "
// " ads--SectionWidget { border: 1px solid #00ff00; background: #E6FFE6; padding: 6px; } "
// " ads--SectionTitleWidget { border: 1px solid #0000ff; background: #E6E6FF; padding: 6px; } "
// " ads--SectionTitleWidget[activeTab=\"true\"] { border: 1px solid #0000ff; background: #9696FF; padding: 6px; } "
// " ads--SectionContentWidget { border: 1px solid #FFFF00; background: #FFFFE6; padding: 6px; } "
// );
//static void centerWidget(QWidget* widget)
//{
// if (widget)
// {
// QDesktopWidget deskWidget;
// const int screenIndex = deskWidget.primaryScreen();
// const QRect deskRect = deskWidget.availableGeometry(screenIndex);
// const int x = (deskRect.width() - widget->rect().width()) / 2;
// const int y = (deskRect.height() - widget->rect().height()) / 2;
// widget->move(x, y);
// }
//}
//static void resizeWidgetPerCent(QWidget* widget, qreal widthPC, qreal heightPC)
//{
// if (widget && widthPC >= 0.0 && heightPC >= 0.0)
// {
// QDesktopWidget deskWidget;
// const int screenIndex = deskWidget.primaryScreen();
// const QRect deskRect = deskWidget.availableGeometry(screenIndex);
// const int w = (deskRect.width() / 100) * widthPC;
// const int h = (deskRect.height() / 100) * heightPC;
// widget->resize(w, h);
// }
//}

View File

@ -47,6 +47,7 @@ static ADS_NS::SectionContent::RefPtr createCalendarSC(ADS_NS::ContainerWidget*
static ADS_NS::SectionContent::RefPtr createFileSystemTreeSC(ADS_NS::ContainerWidget* container)
{
QTreeView* w = new QTreeView();
w->setFrameShape(QFrame::NoFrame);
// QFileSystemModel* m = new QFileSystemModel(w);
// m->setRootPath(QDir::currentPath());
// w->setModel(m);
@ -84,14 +85,8 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->mainToolBar->hide();
ui->statusBar->hide();
#if QT_VERSION >= 0x050000
QObject::connect(ui->actionAddSectionContent, &QAction::triggered, this, &MainWindow::onActionAddSectionContentTriggered);
#else
QObject::connect(ui->actionAddSectionContent, SIGNAL(triggered(bool)), this, SLOT(onActionAddSectionContentTriggered()));
#endif
// ADS - Create main container (ContainerWidget).
_container = new ADS_NS::ContainerWidget();
_container->setOrientation(Qt::Vertical);
#if QT_VERSION >= 0x050000
@ -101,6 +96,7 @@ MainWindow::MainWindow(QWidget *parent) :
#endif
setCentralWidget(_container);
// ADS - Adding some contents.
// Test #1: Use high-level public API
if (true)
{
@ -111,17 +107,17 @@ MainWindow::MainWindow(QWidget *parent) :
sw = _container->addSectionContent(createCalendarSC(cw), sw, ADS_NS::RightDropArea);
sw = _container->addSectionContent(createFileSystemTreeSC(cw), sw, ADS_NS::CenterDropArea);
// _container->addSectionContent(createCalendarSC(_container));
// _container->addSectionContent(createLongTextLabelSC(_container));
// _container->addSectionContent(createLongTextLabelSC(_container));
// _container->addSectionContent(createLongTextLabelSC(_container));
_container->addSectionContent(createCalendarSC(_container));
_container->addSectionContent(createLongTextLabelSC(_container));
_container->addSectionContent(createLongTextLabelSC(_container));
_container->addSectionContent(createLongTextLabelSC(_container));
}
// Default window geometry
resize(800, 600);
// Restore window geometry and ContainerWidget state from last session
restoreGeometry(loadDataHelper("MainWindow"));
// ADS - Restore geometries and states of contents.
_container->restoreState(loadDataHelper("ContainerWidget"));
}

View File

@ -14,15 +14,6 @@
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget"/>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionAddSectionContent"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
@ -33,12 +24,54 @@
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
<string>View</string>
</property>
<addaction name="actionDemo_1"/>
<addaction name="actionDemo_2"/>
<addaction name="actionDemo_3"/>
</widget>
<widget class="QMenu" name="menuAbout">
<property name="title">
<string>About</string>
</property>
</widget>
<addaction name="menuFile"/>
<addaction name="menuView"/>
<addaction name="menuAbout"/>
</widget>
<action name="actionAddSectionContent">
<property name="text">
<string>Add SectionContent</string>
</property>
</action>
<action name="actionDemo_1">
<property name="text">
<string>Demo 1</string>
</property>
</action>
<action name="actionDemo_2">
<property name="text">
<string>Demo 2</string>
</property>
</action>
<action name="actionDemo_3">
<property name="text">
<string>Demo 3</string>
</property>
</action>
<action name="actionExit">
<property name="text">
<string>Exit</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>

View File

@ -3,8 +3,8 @@ Manages content widgets more like Visual Studio or similar programs.
I also try to get everything done with basic Qt functionality.
Basic usage of QWidgets an QLayouts and using basic styles as much as possible.
![Layout of widgets](preview01.png)
![Dropping widgets](preview02.png)
![Layout of widgets](preview.png)
![Dropping widgets](preview-dragndrop.png)
## Tested Compatible Environments
- Windows 10 / Qt 5.5.1 / VC12

BIN
preview-dragndrop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

BIN
preview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB