diff --git a/BASuite/appcore/fancytabwidget.cpp b/BASuite/appcore/fancytabwidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec3f93a0cf6b17a43bfd5d3849d388ddd56421df --- /dev/null +++ b/BASuite/appcore/fancytabwidget.cpp @@ -0,0 +1,149 @@ +#include "fancytabwidget.h" +#include "fancytabbar.h" +//#include "styledbar.h" +#include "stylehelper.h" + +#include <QColorDialog> +#include <QHBoxLayout> +#include <QVBoxLayout> +#include <QMouseEvent> +#include <QStackedLayout> +#include <QStatusBar> +#include <QPainter> +#include <QStackedWidget> + + +class FancyColorButton : public QWidget +{ +public: + FancyColorButton(QWidget *parent) + : m_parent(parent) + { + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); + } + + void mousePressEvent(QMouseEvent *ev) + { + if (ev->modifiers() & Qt::ShiftModifier) { + QColor color = QColorDialog::getColor(StyleHelper::requestedBaseColor(), m_parent); + if (color.isValid()) + StyleHelper::setBaseColor(color); + } + } +private: + QWidget *m_parent; +}; + + +FancyTabWidget::FancyTabWidget(QWidget *parent) + : QWidget(parent) + , m_tabBar(0) +{ + +// m_tabBar = new FancyTabBar(this); + m_tabBar = new FancyTabBar2(this); + + m_selectionWidget = new QWidget(this); + QVBoxLayout *selectionLayout = new QVBoxLayout; + selectionLayout->setSpacing(0); + selectionLayout->setMargin(0); + +// StyledBar *bar = new StyledBar(this); +// QHBoxLayout *layout = new QHBoxLayout(bar); +// layout->setMargin(0); +// layout->setSpacing(10); + //layout->addWidget(new FancyColorButton(this)); + +// selectionLayout->addWidget(bar); + selectionLayout->addWidget(m_tabBar); + m_selectionWidget->setLayout(selectionLayout); + m_selectionWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + + m_cornerWidgetContainer = new QWidget(this); + m_cornerWidgetContainer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); + m_cornerWidgetContainer->setAutoFillBackground(true); //true + + QVBoxLayout *cornerWidgetLayout = new QVBoxLayout; + cornerWidgetLayout->setSpacing(0); + cornerWidgetLayout->setMargin(0); + cornerWidgetLayout->addStretch(); + m_cornerWidgetContainer->setLayout(cornerWidgetLayout); + + selectionLayout->addWidget(m_cornerWidgetContainer, 0); + +// m_modesStack = new QStackedLayout; + m_statusBar = new QStatusBar; + m_statusBar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); + m_statusBar->showMessage("Hello world"); + //m_statusBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + + QVBoxLayout *vlayout = new QVBoxLayout; + vlayout->setMargin(0); + vlayout->setSpacing(0); +// vlayout->addLayout(m_modesStack); +// vlayout->addWidget(m_statusBar); + + + m_stackedWidgets = new QStackedWidget; +// m_stackedWidgets->addWidget(new ConfigurationPage); +// m_stackedWidgets->addWidget(new UpdatePage); +// m_stackedWidgets->addWidget(new QueryPage); + + vlayout->addWidget(m_stackedWidgets, 1); + vlayout->addWidget(m_statusBar); + + QHBoxLayout *mainLayout = new QHBoxLayout; + mainLayout->setMargin(0); + mainLayout->setSpacing(1); + mainLayout->addWidget(m_selectionWidget); + mainLayout->addLayout(vlayout); + setLayout(mainLayout); + + connect(m_tabBar, SIGNAL(currentChanged(int)), this, SLOT(showWidget(int))); + +} + + +FancyTabWidget::~FancyTabWidget() +{ + delete m_tabBar; +} + + +void FancyTabWidget::insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label) +{ + m_stackedWidgets->addWidget(tab); + m_tabBar->insertTab(index, icon, label); + m_tabBar->setTabEnabled(index, true); +} + +//void FancyTabWidget::removeTab(int index) +//{ +// m_modesStack->removeWidget(m_modesStack->widget(index)); +// m_tabBar->removeTab(index); +//} + + +void FancyTabWidget::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event) + QPainter painter(this); + + QRect rect = m_selectionWidget->rect().adjusted(0, 0, 1, 0); + rect = style()->visualRect(layoutDirection(), geometry(), rect); + StyleHelper::verticalGradient(&painter, rect, rect); + painter.setPen(StyleHelper::borderColor()); + painter.drawLine(rect.topRight(), rect.bottomRight()); + + QColor light = StyleHelper::sidebarHighlight(); + painter.setPen(light); + painter.drawLine(rect.bottomLeft(), rect.bottomRight()); +} + + +void FancyTabWidget::showWidget(int index) +{ + emit currentAboutToShow(index); + m_stackedWidgets->setCurrentIndex(index); + emit currentChanged(index); +} diff --git a/BASuite/appcore/fancytabwidget.h b/BASuite/appcore/fancytabwidget.h new file mode 100644 index 0000000000000000000000000000000000000000..2c85c2aa6c556626a3066b5e749ba0ff179be8da --- /dev/null +++ b/BASuite/appcore/fancytabwidget.h @@ -0,0 +1,47 @@ +#ifndef FANCYTABWIDGET_H +#define FANCYTABWIDGET_H + +#include <QWidget> + +class FancyTabBar; +class FancyTabBar2; +class QStackedLayout; +class QStatusBar; +class QStackedWidget; +class QIcon; + + +class FancyTabWidget : public QWidget +{ + Q_OBJECT + +public: + FancyTabWidget(QWidget *parent = 0); + ~FancyTabWidget(); + + void paintEvent(QPaintEvent *event); + + void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label); +// void removeTab(int index); + +signals: + void currentAboutToShow(int index); + void currentChanged(int index); + +public slots: + +private slots: + void showWidget(int index); + +private: + + FancyTabBar2 *m_tabBar; +// FancyTabBar *m_tabBar; + QWidget *m_cornerWidgetContainer; + QWidget *m_selectionWidget; + QStatusBar *m_statusBar; + QStackedWidget *m_stackedWidgets; + +}; + +#endif // FANCYTABWIDGET_H diff --git a/BASuite/appcore/imode.cpp b/BASuite/appcore/imode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..da21e3f36ddf4a54478e806759aec1033509839b --- /dev/null +++ b/BASuite/appcore/imode.cpp @@ -0,0 +1,18 @@ +#include "imode.h" + +IMode::IMode(QObject *parent) : m_isEnabled(true) +{ + (void)parent; +} + +void IMode::setEnabled(bool enabled) +{ + if (m_isEnabled == enabled) return; + m_isEnabled = enabled; + emit enabledStateChanged(m_isEnabled); +} + +bool IMode::isEnabled() const +{ + return m_isEnabled; +} diff --git a/BASuite/appcore/imode.h b/BASuite/appcore/imode.h new file mode 100644 index 0000000000000000000000000000000000000000..04ec8e2fc8ff3387128eb5e21c73d25fb60fdfda --- /dev/null +++ b/BASuite/appcore/imode.h @@ -0,0 +1,36 @@ +#ifndef IMODE_H +#define IMODE_H + +#include <QObject> +#include <QIcon> + +class IMode : public QObject +{ + Q_OBJECT + +public: + IMode(QObject *parent = 0); + + QString displayName() const { return m_displayName; } + QIcon icon() const { return m_icon; } + + int id() const { return m_id; } + bool isEnabled() const; + + void setEnabled(bool enabled); + void setDisplayName(const QString &displayName) { m_displayName = displayName; } + void setIcon(const QIcon &icon) { m_icon = icon; } + void setId(int id) { m_id = id; } + +signals: + void enabledStateChanged(bool enabled); + +private: + QString m_displayName; + QIcon m_icon; + int m_id; + bool m_isEnabled; +}; + + +#endif // IMODE_H diff --git a/BASuite/appcore/main.cpp b/BASuite/appcore/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9e2d83c83caae79d03bee45c85fadf255813fabc --- /dev/null +++ b/BASuite/appcore/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include <QApplication> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/BASuite/appcore/mainwindow.cpp b/BASuite/appcore/mainwindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..768faaef3c627fdeefe7432897a81980eecb98d1 --- /dev/null +++ b/BASuite/appcore/mainwindow.cpp @@ -0,0 +1,51 @@ +#include "mainwindow.h" +#include "fancytabwidget.h" +//#include "manhattanstyle.h" +#include "welcomemanager.h" +#include "samplemanager.h" +#include "experimentmanager.h" +#include "simulationmanager.h" +#include "fitmanager.h" + +#include <QApplication> +#include <iostream> + +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) +// : FancyMainWindow(parent) + , m_tabWidget(0) + , m_welcomeManager(0) + , m_sampleManager(0) + , m_expManager(0) + , m_simulManager(0) + , m_fitManager(0) +{ +// QString baseName = QApplication::style()->objectName(); +// qApp->setStyle(new ManhattanStyle(baseName)); +// std::cout << "XXX " << baseName.toStdString().c_str() << std::endl; + + setDockNestingEnabled(true); + + setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); + setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea); + + m_tabWidget = new FancyTabWidget(this); + m_welcomeManager = new WelcomeManager(); + m_sampleManager = new SampleManager(); + m_expManager = new ExperimentManager(); + m_simulManager = new SimulationManager(); + m_fitManager = new FitManager(); + + m_tabWidget->insertTab(0, m_welcomeManager, QIcon("./images/mode_welcome.png"), "Welcome"); + m_tabWidget->insertTab(1, m_sampleManager, QIcon("./images/mode_sample.png"), "Sample"); + m_tabWidget->insertTab(2, m_expManager, QIcon("./images/mode_exp.png"), "Experiment"); + m_tabWidget->insertTab(3, m_simulManager, QIcon("./images/mode_simul.png"), "Simulation"); + m_tabWidget->insertTab(4, m_fitManager, QIcon("./images/mode_fit.png"), "Fit"); + + setCentralWidget(m_tabWidget); + +} + +MainWindow::~MainWindow() +{ + +} diff --git a/BASuite/appcore/mainwindow.h b/BASuite/appcore/mainwindow.h new file mode 100644 index 0000000000000000000000000000000000000000..66d86fa2cce12d7de6162448b6b670ac884be22c --- /dev/null +++ b/BASuite/appcore/mainwindow.h @@ -0,0 +1,32 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +//#include "fancymainwindow.h" + +class FancyTabWidget; +class WelcomeManager; +class SampleManager; +class ExperimentManager; +class SimulationManager; +class FitManager; + +class MainWindow : public QMainWindow +//class MainWindow : public FancyMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private: + FancyTabWidget *m_tabWidget; + WelcomeManager *m_welcomeManager; + SampleManager *m_sampleManager; + ExperimentManager *m_expManager; + SimulationManager *m_simulManager; + FitManager * m_fitManager; +}; + +#endif // MAINWINDOW_H diff --git a/BASuite/appcore/welcomemode.cpp b/BASuite/appcore/welcomemode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cbdab350bf913db08881d4d473067d060b43079f --- /dev/null +++ b/BASuite/appcore/welcomemode.cpp @@ -0,0 +1,18 @@ +#include "welcomemode.h" +#include "welcomemanager.h" + +WelcomeMode::WelcomeMode() +{ + m_welcomeManager = new WelcomeManager(); + setObjectName(QLatin1String("WelcomeMode")); + setDisplayName(tr("Welcome")); + setIcon(QIcon(QLatin1String(":/fancyactionbar/images/mode_Edit.png"))); + +} + + +WelcomeMode::~WelcomeMode() +{ + // Make sure the editor manager does not get deleted + m_welcomeManager->setParent(0); +} diff --git a/BASuite/appcore/welcomemode.h b/BASuite/appcore/welcomemode.h new file mode 100644 index 0000000000000000000000000000000000000000..00604a704c89ef88a6dc4f6963bf009fe44c8232 --- /dev/null +++ b/BASuite/appcore/welcomemode.h @@ -0,0 +1,17 @@ +#ifndef WELCOMEMODE_H +#define WELCOMEMODE_H + +#include "imode.h" +class WelcomeManager; + +class WelcomeMode : public IMode +{ +public: + WelcomeMode(); + ~WelcomeMode(); + +private: + WelcomeManager *m_welcomeManager; +}; + +#endif // WELCOMEMODE_H diff --git a/BASuite/basuite.pro b/BASuite/basuite.pro new file mode 100644 index 0000000000000000000000000000000000000000..c68191e7451375b4d860eadeb085c8076c7d76c7 --- /dev/null +++ b/BASuite/basuite.pro @@ -0,0 +1,53 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2013-02-11T18:32:10 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = basuite +TEMPLATE = app + +SOURCES += \ + appcore/fancytabwidget.cpp \ + appcore/imode.cpp \ + appcore/main.cpp \ + appcore/mainwindow.cpp \ + appcore/welcomemode.cpp \ + experimentmanager/experimentmanager.cpp \ + fitmanager/fitmanager.cpp \ + samplemanager/samplemanager.cpp \ + simulationmanager/simulationmanager.cpp \ +# utils/fancymainwindow.cpp \ + utils/fancytab.cpp \ + utils/fancytabbar.cpp \ +# utils/manhattanstyle.cpp \ +# utils/styleanimator.cpp \ +# utils/styledbar.cpp \ + utils/stylehelper.cpp \ + welcomemanager/welcomemanager.cpp + +HEADERS += \ + appcore/fancytabwidget.h \ + appcore/imode.h \ + appcore/mainwindow.h \ + appcore/welcomemode.h \ + experimentmanager/experimentmanager.h \ + fitmanager/fitmanager.h \ + samplemanager/samplemanager.h \ + simulationmanager/simulationmanager.h \ +# utils/fancymainwindow.h \ + utils/fancytab.h \ + utils/fancytabbar.h \ +# utils/manhattanstyle.h \ +# utils/styleanimator.h \ +# utils/styledbar.h \ + utils/stylehelper.h \ + welcomemanager/welcomemanager.h + +INCLUDEPATH += $$PWD/utils $$PWD/appcore $$PWD/welcomemanager $$PWD/samplemanager $$PWD/experimentmanager $$PWD/simulationmanager $$PWD/fitmanager + +#FORMS += mainwindow.ui diff --git a/BASuite/experimentmanager/experimentmanager.cpp b/BASuite/experimentmanager/experimentmanager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b03305e0a4ce9c6488037f89764aed81f6ac9419 --- /dev/null +++ b/BASuite/experimentmanager/experimentmanager.cpp @@ -0,0 +1,45 @@ +#include "experimentmanager.h" +#include <QtWidgets> + +ExperimentManager::ExperimentManager(QWidget *parent) + : QWidget(parent) +{ + QGroupBox *packagesGroup = new QGroupBox(tr("Look for packages")); + + QLabel *nameLabel = new QLabel(tr("Name:")); + QLineEdit *nameEdit = new QLineEdit; + + QLabel *dateLabel = new QLabel(tr("Released after:")); + QDateTimeEdit *dateEdit = new QDateTimeEdit(QDate::currentDate()); + + QCheckBox *releasesCheckBox = new QCheckBox(tr("Releases")); + QCheckBox *upgradesCheckBox = new QCheckBox(tr("Upgrades")); + + QSpinBox *hitsSpinBox = new QSpinBox; + hitsSpinBox->setPrefix(tr("Return up to ")); + hitsSpinBox->setSuffix(tr(" results")); + hitsSpinBox->setSpecialValueText(tr("Return only the first result")); + hitsSpinBox->setMinimum(1); + hitsSpinBox->setMaximum(100); + hitsSpinBox->setSingleStep(10); + + QPushButton *startQueryButton = new QPushButton(tr("Start query")); + + QGridLayout *packagesLayout = new QGridLayout; + packagesLayout->addWidget(nameLabel, 0, 0); + packagesLayout->addWidget(nameEdit, 0, 1); + packagesLayout->addWidget(dateLabel, 1, 0); + packagesLayout->addWidget(dateEdit, 1, 1); + packagesLayout->addWidget(releasesCheckBox, 2, 0); + packagesLayout->addWidget(upgradesCheckBox, 3, 0); + packagesLayout->addWidget(hitsSpinBox, 4, 0, 1, 2); + packagesGroup->setLayout(packagesLayout); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(packagesGroup); + mainLayout->addSpacing(12); + mainLayout->addWidget(startQueryButton); + mainLayout->addStretch(1); + setLayout(mainLayout); +} + diff --git a/BASuite/experimentmanager/experimentmanager.h b/BASuite/experimentmanager/experimentmanager.h new file mode 100644 index 0000000000000000000000000000000000000000..b49f575b149d992fcddf8876872010c1686d1519 --- /dev/null +++ b/BASuite/experimentmanager/experimentmanager.h @@ -0,0 +1,12 @@ +#ifndef EXPMANAGER_H +#define EXPMANAGER_H + +#include <QWidget> + +class ExperimentManager : public QWidget +{ +public: + ExperimentManager(QWidget *parent = 0); +}; + +#endif // EXPMANAGER_H diff --git a/BASuite/fitmanager/fitmanager.cpp b/BASuite/fitmanager/fitmanager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..58683aa92277521bf59508c811d0e915abe931c0 --- /dev/null +++ b/BASuite/fitmanager/fitmanager.cpp @@ -0,0 +1,46 @@ +#include "fitmanager.h" +#include <QtWidgets> + + +FitManager::FitManager(QWidget *parent) + : QWidget(parent) +{ + QGroupBox *packagesGroup = new QGroupBox(tr("Look for packages")); + + QLabel *nameLabel = new QLabel(tr("Name:")); + QLineEdit *nameEdit = new QLineEdit; + + QLabel *dateLabel = new QLabel(tr("Released after:")); + QDateTimeEdit *dateEdit = new QDateTimeEdit(QDate::currentDate()); + + QCheckBox *releasesCheckBox = new QCheckBox(tr("Releases")); + QCheckBox *upgradesCheckBox = new QCheckBox(tr("Upgrades")); + + QSpinBox *hitsSpinBox = new QSpinBox; + hitsSpinBox->setPrefix(tr("Return up to ")); + hitsSpinBox->setSuffix(tr(" results")); + hitsSpinBox->setSpecialValueText(tr("Return only the first result")); + hitsSpinBox->setMinimum(1); + hitsSpinBox->setMaximum(100); + hitsSpinBox->setSingleStep(10); + + QPushButton *startQueryButton = new QPushButton(tr("Start query")); + + QGridLayout *packagesLayout = new QGridLayout; + packagesLayout->addWidget(nameLabel, 0, 0); + packagesLayout->addWidget(nameEdit, 0, 1); + packagesLayout->addWidget(dateLabel, 1, 0); + packagesLayout->addWidget(dateEdit, 1, 1); + packagesLayout->addWidget(releasesCheckBox, 2, 0); + packagesLayout->addWidget(upgradesCheckBox, 3, 0); + packagesLayout->addWidget(hitsSpinBox, 4, 0, 1, 2); + packagesGroup->setLayout(packagesLayout); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(packagesGroup); + mainLayout->addSpacing(12); + mainLayout->addWidget(startQueryButton); + mainLayout->addStretch(1); + setLayout(mainLayout); +} + diff --git a/BASuite/fitmanager/fitmanager.h b/BASuite/fitmanager/fitmanager.h new file mode 100644 index 0000000000000000000000000000000000000000..608f2024de0bb30d4304d3b5e2ad8ecc84b85471 --- /dev/null +++ b/BASuite/fitmanager/fitmanager.h @@ -0,0 +1,14 @@ +#ifndef FITMANAGER_H +#define FITMANAGER_H + +#include <QWidget> + + +class FitManager : public QWidget +{ +public: + FitManager(QWidget *parent = 0); +}; + + +#endif // FITMANAGER_H diff --git a/BASuite/images/mode_exp.png b/BASuite/images/mode_exp.png new file mode 100644 index 0000000000000000000000000000000000000000..994520b8b53e344f4424c3c32f6872fccaa5427b Binary files /dev/null and b/BASuite/images/mode_exp.png differ diff --git a/BASuite/images/mode_fit.png b/BASuite/images/mode_fit.png new file mode 100644 index 0000000000000000000000000000000000000000..e095ab64d8e186d5ecbdf13e166f00e913adbee5 Binary files /dev/null and b/BASuite/images/mode_fit.png differ diff --git a/BASuite/images/mode_sample.png b/BASuite/images/mode_sample.png new file mode 100644 index 0000000000000000000000000000000000000000..fd388db826174d63dcafa57b5db5724b0b62ae12 Binary files /dev/null and b/BASuite/images/mode_sample.png differ diff --git a/BASuite/images/mode_simul.png b/BASuite/images/mode_simul.png new file mode 100644 index 0000000000000000000000000000000000000000..2d9abbdd56f1d44ec0f1992ab3252c2849f4c929 Binary files /dev/null and b/BASuite/images/mode_simul.png differ diff --git a/BASuite/images/mode_welcome.png b/BASuite/images/mode_welcome.png new file mode 100644 index 0000000000000000000000000000000000000000..a14a2e6d4a41a639a5ddbbabdd5776e78c6ff306 Binary files /dev/null and b/BASuite/images/mode_welcome.png differ diff --git a/BASuite/samplemanager/samplemanager.cpp b/BASuite/samplemanager/samplemanager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..800eb9a52324ff7075fa8055d247b2d4c58500b5 --- /dev/null +++ b/BASuite/samplemanager/samplemanager.cpp @@ -0,0 +1,42 @@ +#include "samplemanager.h" +#include <QtWidgets> + + +SampleManager::SampleManager(QWidget *parent) + : QWidget(parent) +{ + QGroupBox *updateGroup = new QGroupBox(tr("Package selection")); + QCheckBox *systemCheckBox = new QCheckBox(tr("Update system")); + QCheckBox *appsCheckBox = new QCheckBox(tr("Update applications")); + QCheckBox *docsCheckBox = new QCheckBox(tr("Update documentation")); + + QGroupBox *packageGroup = new QGroupBox(tr("Existing packages")); + + QListWidget *packageList = new QListWidget; + QListWidgetItem *qtItem = new QListWidgetItem(packageList); + qtItem->setText(tr("Qt")); + QListWidgetItem *qsaItem = new QListWidgetItem(packageList); + qsaItem->setText(tr("QSA")); + QListWidgetItem *teamBuilderItem = new QListWidgetItem(packageList); + teamBuilderItem->setText(tr("Teambuilder")); + + QPushButton *startUpdateButton = new QPushButton(tr("Start update")); + + QVBoxLayout *updateLayout = new QVBoxLayout; + updateLayout->addWidget(systemCheckBox); + updateLayout->addWidget(appsCheckBox); + updateLayout->addWidget(docsCheckBox); + updateGroup->setLayout(updateLayout); + + QVBoxLayout *packageLayout = new QVBoxLayout; + packageLayout->addWidget(packageList); + packageGroup->setLayout(packageLayout); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(updateGroup); + mainLayout->addWidget(packageGroup); + mainLayout->addSpacing(12); + mainLayout->addWidget(startUpdateButton); + mainLayout->addStretch(1); + setLayout(mainLayout); +} diff --git a/BASuite/samplemanager/samplemanager.h b/BASuite/samplemanager/samplemanager.h new file mode 100644 index 0000000000000000000000000000000000000000..3199dab5a64204448ee908380741fc227bf7fa1e --- /dev/null +++ b/BASuite/samplemanager/samplemanager.h @@ -0,0 +1,12 @@ +#ifndef SAMPLEMANAGER_H +#define SAMPLEMANAGER_H + +#include <QWidget> + +class SampleManager : public QWidget +{ +public: + SampleManager(QWidget *parent = 0); +}; + +#endif // SAMPLEMANAGER_H diff --git a/BASuite/simulationmanager/simulationmanager.cpp b/BASuite/simulationmanager/simulationmanager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0d94dc8ddb3300725c300b1d3093d6e5eca994a4 --- /dev/null +++ b/BASuite/simulationmanager/simulationmanager.cpp @@ -0,0 +1,42 @@ +#include "simulationmanager.h" +#include <QtWidgets> + + +SimulationManager::SimulationManager(QWidget *parent) + : QWidget(parent) +{ + QGroupBox *updateGroup = new QGroupBox(tr("Package selection")); + QCheckBox *systemCheckBox = new QCheckBox(tr("Update system")); + QCheckBox *appsCheckBox = new QCheckBox(tr("Update applications")); + QCheckBox *docsCheckBox = new QCheckBox(tr("Update documentation")); + + QGroupBox *packageGroup = new QGroupBox(tr("Existing packages")); + + QListWidget *packageList = new QListWidget; + QListWidgetItem *qtItem = new QListWidgetItem(packageList); + qtItem->setText(tr("Qt")); + QListWidgetItem *qsaItem = new QListWidgetItem(packageList); + qsaItem->setText(tr("QSA")); + QListWidgetItem *teamBuilderItem = new QListWidgetItem(packageList); + teamBuilderItem->setText(tr("Teambuilder")); + + QPushButton *startUpdateButton = new QPushButton(tr("Start update")); + + QVBoxLayout *updateLayout = new QVBoxLayout; + updateLayout->addWidget(systemCheckBox); + updateLayout->addWidget(appsCheckBox); + updateLayout->addWidget(docsCheckBox); + updateGroup->setLayout(updateLayout); + + QVBoxLayout *packageLayout = new QVBoxLayout; + packageLayout->addWidget(packageList); + packageGroup->setLayout(packageLayout); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(updateGroup); + mainLayout->addWidget(packageGroup); + mainLayout->addSpacing(12); + mainLayout->addWidget(startUpdateButton); + mainLayout->addStretch(1); + setLayout(mainLayout); +} diff --git a/BASuite/simulationmanager/simulationmanager.h b/BASuite/simulationmanager/simulationmanager.h new file mode 100644 index 0000000000000000000000000000000000000000..aa9ae6d12cfa9eab9d610cf7c2740aa3c43f0294 --- /dev/null +++ b/BASuite/simulationmanager/simulationmanager.h @@ -0,0 +1,14 @@ +#ifndef SIMULATIONMANAGER_H +#define SIMULATIONMANAGER_H + +#include <QWidget> + + +class SimulationManager : public QWidget +{ +public: + SimulationManager(QWidget *parent = 0); +}; + + +#endif // SIMULATIONMANAGER_H diff --git a/BASuite/utils/fancytab.cpp b/BASuite/utils/fancytab.cpp new file mode 100644 index 0000000000000000000000000000000000000000..211d84ed4bb7e1f691e255b8249243d81b18f8e3 --- /dev/null +++ b/BASuite/utils/fancytab.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "fancytab.h" + +//void FancyTab::fadeIn() +//{ +// mAnimator.stop(); +// mAnimator.setDuration(80); +// mAnimator.setEndValue(40); +// mAnimator.start(); +//} + +//void FancyTab::fadeOut() +//{ +// mAnimator.stop(); +// mAnimator.setDuration(160); +// mAnimator.setEndValue(0); +// mAnimator.start(); +//} + +//void FancyTab::setFader(float value) +//{ +// mFader = value; +// mTabBar->update(); +//} + + +void FancyTab::fadeIn() +{ + animator.stop(); + animator.setDuration(80); + animator.setEndValue(40); + animator.start(); +} + +void FancyTab::fadeOut() +{ + animator.stop(); + animator.setDuration(160); + animator.setEndValue(0); + animator.start(); +} + +void FancyTab::setFader(float value) +{ + m_fader = value; + tabbar->update(); +} diff --git a/BASuite/utils/fancytab.h b/BASuite/utils/fancytab.h new file mode 100644 index 0000000000000000000000000000000000000000..b1275ad5bf5ba9de4dbeaeacea4c9be32ba9b272 --- /dev/null +++ b/BASuite/utils/fancytab.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef FANCYTAB_H +#define FANCYTAB_H + +#include <QIcon> +#include <QWidget> + +#include <QPropertyAnimation> + +//class FancyTab : public QObject +//{ +// Q_OBJECT + +// Q_PROPERTY(float fader READ fader WRITE setFader) +//public: +// FancyTab(QWidget *tabbar) : enabled(false), mTabBar(tabbar), mFader(0) +// { +// mAnimator.setPropertyName("fader"); +// mAnimator.setTargetObject(this); +// } + +// float fader() { return mFader; } +// void setFader(float value); + +// void fadeIn(); +// void fadeOut(); + +// QIcon icon; +// QString text; +// QString toolTip; +// bool enabled; + +//private: +// QPropertyAnimation mAnimator; +// QWidget *mTabBar; +// float mFader; +//}; + +class FancyTab : public QObject +{ + Q_OBJECT + + Q_PROPERTY(float fader READ fader WRITE setFader) +public: + FancyTab(QWidget *tabbar) : enabled(false), tabbar(tabbar), m_fader(0) { + animator.setPropertyName("fader"); + animator.setTargetObject(this); + } + float fader() { return m_fader; } + void setFader(float value); + + void fadeIn(); + void fadeOut(); + + QIcon icon; + QString text; + QString toolTip; + bool enabled; + +private: + QPropertyAnimation animator; + QWidget *tabbar; + float m_fader; +}; + + +#endif // FANCYTAB_H diff --git a/BASuite/utils/fancytabbar.cpp b/BASuite/utils/fancytabbar.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db87f80d031c5d3d2006d0fe89e3ff6b3de38c0a --- /dev/null +++ b/BASuite/utils/fancytabbar.cpp @@ -0,0 +1,742 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "fancytabbar.h" +#include "stylehelper.h" + +#include <QMouseEvent> +//#include <QWindowsStyle> +#include <QPainter> +#include <QColor> +#include <QStackedLayout> +#include <QToolTip> +#include <QStyleFactory> + +const int FancyTabBar::m_rounding = 22; +const int FancyTabBar::m_textPadding = 4; + +FancyTabBar::FancyTabBar(QWidget *parent) + : QWidget(parent) +{ + m_hoverIndex = -1; + m_currentIndex = -1; + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); + setStyle(QStyleFactory::create(QLatin1String("windows"))); + setMinimumWidth(qMax(2 * m_rounding, 40)); + setAttribute(Qt::WA_Hover, true); + setFocusPolicy(Qt::NoFocus); + setMouseTracking(true); // Needed for hover events + m_triggerTimer.setSingleShot(true); + + // We use a zerotimer to keep the sidebar responsive + connect(&m_triggerTimer, SIGNAL(timeout()), this, SLOT(emitCurrentIndex())); +} + +FancyTabBar::~FancyTabBar() +{ + delete style(); +} + +QSize FancyTabBar::tabSizeHint(bool minimum) const +{ + QFont boldFont(font()); +// boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize()); + boldFont.setPointSizeF(StyleHelper::sidebarFontSize()); + boldFont.setBold(true); + QFontMetrics fm(boldFont); + int spacing = 8; + int width = 60 + spacing + 2; + int maxLabelwidth = 0; + for (int tab=0 ; tab<count() ;++tab) { + int width = fm.width(tabText(tab)); + if (width > maxLabelwidth) + maxLabelwidth = width; + } +// int iconHeight = minimum ? 0 : 32; + int iconHeight = minimum ? 0 : 48; + return QSize(qMax(width, maxLabelwidth + 4), iconHeight + spacing + fm.height()); +} + +void FancyTabBar::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event) + QPainter p(this); + + for (int i = 0; i < count(); ++i) + if (i != currentIndex()) + paintTab(&p, i); + + // paint active tab last, since it overlaps the neighbors + if (currentIndex() != -1) + paintTab(&p, currentIndex()); +} + +// Handle hover events for mouse fade ins +void FancyTabBar::mouseMoveEvent(QMouseEvent *e) +{ + int newHover = -1; + for (int i = 0; i < count(); ++i) { + QRect area = tabRect(i); + if (area.contains(e->pos())) { + newHover = i; + break; + } + } + if (newHover == m_hoverIndex) + return; + + if (validIndex(m_hoverIndex)) + m_tabs[m_hoverIndex]->fadeOut(); + + m_hoverIndex = newHover; + + if (validIndex(m_hoverIndex)) { + m_tabs[m_hoverIndex]->fadeIn(); + m_hoverRect = tabRect(m_hoverIndex); + } +} + +bool FancyTabBar::event(QEvent *event) +{ + if (event->type() == QEvent::ToolTip) { + if (validIndex(m_hoverIndex)) { + QString tt = tabToolTip(m_hoverIndex); + if (!tt.isEmpty()) { + QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), tt, this); + return true; + } + } + } + return QWidget::event(event); +} + +// Resets hover animation on mouse enter +void FancyTabBar::enterEvent(QEvent *e) +{ + Q_UNUSED(e) + m_hoverRect = QRect(); + m_hoverIndex = -1; +} + +// Resets hover animation on mouse enter +void FancyTabBar::leaveEvent(QEvent *e) +{ + Q_UNUSED(e) + m_hoverIndex = -1; + m_hoverRect = QRect(); + for (int i = 0 ; i < m_tabs.count() ; ++i) { + m_tabs[i]->fadeOut(); + } +} + +QSize FancyTabBar::sizeHint() const +{ + QSize sh = tabSizeHint(); + return QSize(sh.width(), sh.height() * m_tabs.count()); +} + +QSize FancyTabBar::minimumSizeHint() const +{ + QSize sh = tabSizeHint(true); + return QSize(sh.width(), sh.height() * m_tabs.count()); +} + +QRect FancyTabBar::tabRect(int index) const +{ + QSize sh = tabSizeHint(); + + if (sh.height() * m_tabs.count() > height()) + sh.setHeight(height() / m_tabs.count()); + + return QRect(0, index * sh.height(), sh.width(), sh.height()); + +} + +// This keeps the sidebar responsive since +// we get a repaint before loading the +// mode itself +void FancyTabBar::emitCurrentIndex() +{ + emit currentChanged(m_currentIndex); +} + +void FancyTabBar::mousePressEvent(QMouseEvent *e) +{ + e->accept(); + for (int index = 0; index < m_tabs.count(); ++index) { + if (tabRect(index).contains(e->pos())) { + + if (isTabEnabled(index)) { + m_currentIndex = index; + update(); + m_triggerTimer.start(0); + } + break; + } + } +} + +void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const +{ + if (!validIndex(tabIndex)) { + qWarning("invalid index"); + return; + } + painter->save(); + + QRect rect = tabRect(tabIndex); + bool selected = (tabIndex == m_currentIndex); + bool enabled = isTabEnabled(tabIndex); + + if (selected) { + //background + painter->save(); + QLinearGradient grad(rect.topLeft(), rect.topRight()); + grad.setColorAt(0, QColor(255, 255, 255, 140)); + grad.setColorAt(1, QColor(255, 255, 255, 210)); + painter->fillRect(rect.adjusted(0, 0, 0, -1), grad); + painter->restore(); + + //shadows + painter->setPen(QColor(0, 0, 0, 110)); + painter->drawLine(rect.topLeft() + QPoint(1,-1), rect.topRight() - QPoint(0,1)); + painter->drawLine(rect.bottomLeft(), rect.bottomRight()); + painter->setPen(QColor(0, 0, 0, 40)); + painter->drawLine(rect.topLeft(), rect.bottomLeft()); + + //highlights + painter->setPen(QColor(255, 255, 255, 50)); + painter->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0,2)); + painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0,1)); + painter->setPen(QColor(255, 255, 255, 40)); + painter->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight()); + painter->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1)); + painter->drawLine(rect.bottomLeft() + QPoint(0,-1), rect.bottomRight()-QPoint(0,1)); + } + + QString tabText(this->tabText(tabIndex)); + QRect tabTextRect(tabRect(tabIndex)); + QRect tabIconRect(tabTextRect); + tabTextRect.translate(0, -2); + QFont boldFont(painter->font()); +// boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize()); + boldFont.setPointSizeF(StyleHelper::sidebarFontSize()); + boldFont.setBold(true); + painter->setFont(boldFont); + painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110)); + int textFlags = Qt::AlignCenter | Qt::AlignBottom | Qt::TextWordWrap; + if (enabled) { + painter->drawText(tabTextRect, textFlags, tabText); + painter->setPen(selected ? QColor(60, 60, 60) : StyleHelper::panelTextColor()); + } else { + painter->setPen(selected ? StyleHelper::panelTextColor() : QColor(255, 255, 255, 120)); + } +#ifndef Q_OS_MAC + if (!selected && enabled) { + painter->save(); + int fader = int(m_tabs[tabIndex]->fader()); + QLinearGradient grad(rect.topLeft(), rect.topRight()); + grad.setColorAt(0, Qt::transparent); + grad.setColorAt(0.5, QColor(255, 255, 255, fader)); + grad.setColorAt(1, Qt::transparent); + painter->fillRect(rect, grad); + painter->setPen(QPen(grad, 1.0)); + painter->drawLine(rect.topLeft(), rect.topRight()); + painter->drawLine(rect.bottomLeft(), rect.bottomRight()); + painter->restore(); + } +#endif + + if (!enabled) + painter->setOpacity(0.7); + + int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height(); + tabIconRect.adjust(0, 4, 0, -textHeight); + StyleHelper::drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, enabled ? QIcon::Normal : QIcon::Disabled); + + painter->translate(0, -1); + painter->drawText(tabTextRect, textFlags, tabText); + painter->restore(); +} + +void FancyTabBar::setCurrentIndex(int index) { + if (isTabEnabled(index)) { + m_currentIndex = index; + update(); + emit currentChanged(m_currentIndex); + } +} + +void FancyTabBar::setTabEnabled(int index, bool enable) +{ + Q_ASSERT(index < m_tabs.size()); + Q_ASSERT(index >= 0); + + if (index < m_tabs.size() && index >= 0) { + m_tabs[index]->enabled = enable; + update(tabRect(index)); + } +} + +bool FancyTabBar::isTabEnabled(int index) const +{ + Q_ASSERT(index < m_tabs.size()); + Q_ASSERT(index >= 0); + + if (index < m_tabs.size() && index >= 0) + return m_tabs[index]->enabled; + + return false; +} + + + +// ---------------------------------------------------------------------------- +// Another implementation of FancyTabBar which can be places in different corners +// ---------------------------------------------------------------------------- + +const int FancyTabBar2::m_rounding = 22; +const int FancyTabBar2::m_textPadding = 4; + + +FancyTabBar2::FancyTabBar2(QWidget *parent, TabBarPosition position ) + : QWidget(parent), mPosition(position) +{ + mHoverIndex = -1; + mCurrentIndex = -1; + + if(mPosition == Above || mPosition == Below) + { + setMinimumHeight(qMax(2 * m_rounding, 40)); + setMaximumHeight(tabSizeHint(false).height()); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + } + else + { + setMinimumWidth(qMax(2 * m_rounding, 40)); + setMaximumWidth(tabSizeHint(false).width()); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); + } + +// setStyle(new QWindowsStyle); + setStyle(QStyleFactory::create(QLatin1String("windows"))); + + setAttribute(Qt::WA_Hover, true); + setFocusPolicy(Qt::NoFocus); + setMouseTracking(true); // Needed for hover events + mTimerTriggerChangedSignal.setSingleShot(true); + + // We use a zerotimer to keep the sidebar responsive + connect(&mTimerTriggerChangedSignal, SIGNAL(timeout()), this, SLOT(emitCurrentIndex())); +} + +FancyTabBar2::~FancyTabBar2() +{ + delete style(); +} + +QSize FancyTabBar2::tabSizeHint(bool minimum) const +{ + QFont boldFont(font()); + boldFont.setPointSizeF(StyleHelper::sidebarFontSize()); + boldFont.setBold(true); + QFontMetrics fm(boldFont); + int spacing = 8; + int width = 60 + spacing + 2; + int maxLabelwidth = 0; + for (int tab=0 ; tab<count() ;++tab) { + int width = fm.width(tabText(tab)); + if (width > maxLabelwidth) + maxLabelwidth = width; + } + //int iconHeight = minimum ? 0 : 32; + int iconHeight = minimum ? 0 : 48; + + return QSize(qMax(width, maxLabelwidth + 4), iconHeight + spacing + fm.height()); +} + +QPoint FancyTabBar2::getCorner(const QRect& rect, const Corner corner) const +{ + if(mPosition == Above) + { + if(corner == OutsideBeginning) return rect.topLeft(); + if(corner == OutsideEnd) return rect.topRight(); + if(corner == InsideBeginning) return rect.bottomLeft(); + if(corner == InsideEnd) return rect.bottomRight(); + } + else if(mPosition == Below) + { + if(corner == OutsideBeginning) return rect.bottomLeft(); + if(corner == OutsideEnd) return rect.bottomRight(); + if(corner == InsideBeginning) return rect.topLeft(); + if(corner == InsideEnd) return rect.topRight(); + } + else if(mPosition == Left) + { + if(corner == OutsideBeginning) return rect.topLeft(); + if(corner == OutsideEnd) return rect.bottomLeft(); + if(corner == InsideBeginning) return rect.topRight(); + if(corner == InsideEnd) return rect.bottomRight(); + } + else if(mPosition == Right) + { + if(corner == OutsideBeginning) return rect.topRight(); + if(corner == OutsideEnd) return rect.bottomRight(); + if(corner == InsideBeginning) return rect.topLeft(); + if(corner == InsideEnd) return rect.bottomLeft(); + } + + Q_ASSERT("that's impossible!"); + return QPoint(); +} + +QRect FancyTabBar2::adjustRect(const QRect& rect, const qint8 offsetOutside, const qint8 offsetInside, const qint8 offsetBeginning, const qint8 offsetEnd) const +{ + if(mPosition == Above) return rect.adjusted(-offsetBeginning, -offsetOutside, offsetEnd, offsetInside); + else if(mPosition == Below) return rect.adjusted(-offsetBeginning, -offsetInside, -offsetBeginning, offsetOutside); + else if(mPosition == Left) return rect.adjusted(-offsetOutside, -offsetBeginning, offsetInside, offsetEnd); + else if(mPosition == Right) return rect.adjusted(-offsetInside, -offsetBeginning, offsetOutside, offsetEnd); + + Q_ASSERT("that's impossible!"); + return QRect(); +} + +// Same with a point: + means towards Outside/End, - means towards Inside/Beginning +QPoint FancyTabBar2::adjustPoint(const QPoint& point, const qint8 offsetInsideOutside, const qint8 offsetBeginningEnd) const +{ + if(mPosition == Above) return point + QPoint(offsetBeginningEnd, -offsetInsideOutside); + else if(mPosition == Below) return point + QPoint(offsetBeginningEnd, offsetInsideOutside); + else if(mPosition == Left) return point + QPoint(-offsetInsideOutside, offsetBeginningEnd); + else if(mPosition == Right) return point + QPoint(offsetInsideOutside, offsetBeginningEnd); + + Q_ASSERT("that's impossible!"); + return QPoint(); +} + +void FancyTabBar2::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event) + QPainter painter(this); + + // paint background + QRect rectangle = adjustRect(rect(), 0, -1, 0, 0); + QLinearGradient lg; + + lg.setStart(getCorner(rectangle, OutsideBeginning)); + lg.setFinalStop(getCorner(rectangle, InsideBeginning)); + lg.setColorAt(0.0, QColor(64, 64, 64, 255)); + lg.setColorAt(1.0, QColor(130, 130, 130, 255)); + painter.fillRect(rectangle, lg); + + // draw dark widget bordert on inner inside (e.g. bottom if the widget position is top) + painter.setPen(StyleHelper::borderColor()); + painter.drawLine(adjustPoint(getCorner(rectangle, InsideBeginning), -1, 0), adjustPoint(getCorner(rectangle, InsideEnd), -1, 0)); + + // draw bright widget border on outer inside (e.g. bottom if the widget position is top) + painter.setPen(StyleHelper::sidebarHighlight()); + painter.drawLine(getCorner(rectangle, InsideBeginning), getCorner(rectangle, InsideEnd)); + + // paint inactive tabs + for (int i = 0; i < count(); ++i) + if (i != currentIndex()) + paintTab(&painter, i); + + // paint active tab last, since it overlaps the neighbors + if (currentIndex() != -1) + paintTab(&painter, currentIndex()); +} + +// Handle hover events for mouse fade ins +void FancyTabBar2::mouseMoveEvent(QMouseEvent *e) +{ + int newHover = -1; + for (int i = 0; i < count(); ++i) + { + QRect area = tabRect(i); + if (area.contains(e->pos())) { + newHover = i; + break; + } + } + if (newHover == mHoverIndex) + return; + + if (validIndex(mHoverIndex)) + mAttachedTabs[mHoverIndex]->fadeOut(); + + mHoverIndex = newHover; + + if (validIndex(mHoverIndex)) { + mAttachedTabs[mHoverIndex]->fadeIn(); + mHoverRect = tabRect(mHoverIndex); + } +} + +bool FancyTabBar2::event(QEvent *event) +{ + if (event->type() == QEvent::ToolTip) { + if (validIndex(mHoverIndex)) { + QString tt = tabToolTip(mHoverIndex); + if (!tt.isEmpty()) { + QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), tt, this); + return true; + } + } + } + return QWidget::event(event); +} + +// Resets hover animation on mouse enter +void FancyTabBar2::enterEvent(QEvent *e) +{ + Q_UNUSED(e) + mHoverRect = QRect(); + mHoverIndex = -1; +} + +// Resets hover animation on mouse leave +void FancyTabBar2::leaveEvent(QEvent *e) +{ + Q_UNUSED(e) + mHoverIndex = -1; + mHoverRect = QRect(); + for (int i = 0 ; i < mAttachedTabs.count() ; ++i) { + mAttachedTabs[i]->fadeOut(); + } +} + +QSize FancyTabBar2::sizeHint() const +{ + QSize sh = tabSizeHint(); +// return QSize(sh.width(), sh.height() * mAttachedTabs.count()); + + if(mPosition == Above || mPosition == Below) + return QSize(sh.width() * mAttachedTabs.count(), sh.height()); + else + return QSize(sh.width(), sh.height() * mAttachedTabs.count()); +} + +QSize FancyTabBar2::minimumSizeHint() const +{ + QSize sh = tabSizeHint(true); +// return QSize(sh.width(), sh.height() * mAttachedTabs.count()); + + if(mPosition == Above || mPosition == Below) + return QSize(sh.width() * mAttachedTabs.count(), sh.height()); + else + return QSize(sh.width(), sh.height() * mAttachedTabs.count()); +} + +QRect FancyTabBar2::tabRect(int index) const +{ + QSize sh = tabSizeHint(); + + if(mPosition == Above || mPosition == Below) + { + if (sh.width() * mAttachedTabs.count() > width()) + sh.setWidth(width() / mAttachedTabs.count()); + + return QRect(index * sh.width(), 0, sh.width(), sh.height()); + } + else + { + if (sh.height() * mAttachedTabs.count() > height()) + sh.setHeight(height() / mAttachedTabs.count()); + + return QRect(0, index * sh.height(), sh.width(), sh.height()); + } + +} + +// This keeps the sidebar responsive since +// we get a repaint before loading the +// mode itself +void FancyTabBar2::emitCurrentIndex() +{ + emit currentChanged(mCurrentIndex); +} + +void FancyTabBar2::mousePressEvent(QMouseEvent *e) +{ + e->accept(); + for (int index = 0; index < mAttachedTabs.count(); ++index) + { + if (tabRect(index).contains(e->pos())) + { + if (isTabEnabled(index)) + { + mCurrentIndex = index; + update(); + mTimerTriggerChangedSignal.start(0); + } + break; + } + } +} + +void FancyTabBar2::paintTab(QPainter *painter, int tabIndex) const +{ + if (!validIndex(tabIndex)) + { + qWarning("invalid index"); + return; + } + painter->save(); + + QRect rect = tabRect(tabIndex); + bool selected = (tabIndex == mCurrentIndex); + bool enabled = isTabEnabled(tabIndex); + + if(selected) + { + // background + painter->save(); + QLinearGradient grad(getCorner(rect, OutsideBeginning), getCorner(rect, InsideBeginning)); + grad.setColorAt(0, QColor(255, 255, 255, 140)); + grad.setColorAt(1, QColor(255, 255, 255, 210)); + painter->fillRect(adjustRect(rect, 0, 0, 0, -1), grad); + painter->restore(); + + // shadows (the black lines immediately before/after (active && selected)-backgrounds) + painter->setPen(QColor(0, 0, 0, 110)); + painter->drawLine(adjustPoint(getCorner(rect, OutsideBeginning), 0, -1), adjustPoint(getCorner(rect, InsideBeginning), 0, -1)); + painter->drawLine(getCorner(rect, OutsideEnd), getCorner(rect, InsideEnd)); + + // thin shadow on the outside of active tab + painter->setPen(QColor(0, 0, 0, 40)); + painter->drawLine(getCorner(rect, OutsideBeginning), getCorner(rect, OutsideEnd)); + + // highlights + painter->setPen(QColor(255, 255, 255, 50)); + painter->drawLine(adjustPoint(getCorner(rect, OutsideBeginning), 0, -2), adjustPoint(getCorner(rect, InsideBeginning), 0, -2)); + painter->drawLine(adjustPoint(getCorner(rect, OutsideEnd), 0, 1), adjustPoint(getCorner(rect, InsideEnd), 0, 1)); + + painter->setPen(QColor(255, 255, 255, 40)); + // thin white line towards beginning + painter->drawLine(adjustPoint(getCorner(rect, OutsideBeginning), 0, 0), adjustPoint(getCorner(rect, InsideBeginning), 0, 0)); + // thin white line on inside border + painter->drawLine(adjustPoint(getCorner(rect, InsideBeginning), 0, 1), adjustPoint(getCorner(rect, InsideEnd), 0, -1)); + // thin white line towards end + painter->drawLine(adjustPoint(getCorner(rect, OutsideEnd), 0, -1), adjustPoint(getCorner(rect, InsideEnd), 0, -1)); + } + + QString tabText(this->tabText(tabIndex)); + QRect tabTextRect(rect); + const bool drawIcon = rect.height() > 36; + QRect tabIconRect(tabTextRect); + tabTextRect.translate(0, drawIcon ? -2 : 1); + QFont boldFont(painter->font()); + boldFont.setPointSizeF(StyleHelper::sidebarFontSize()); + boldFont.setBold(true); + painter->setFont(boldFont); + painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110)); + const int textFlags = Qt::AlignCenter | (drawIcon ? Qt::AlignBottom : Qt::AlignVCenter) | Qt::TextWordWrap; + if (enabled) { + painter->drawText(tabTextRect, textFlags, tabText); + painter->setPen(selected ? QColor(60, 60, 60) : StyleHelper::panelTextColor()); + } else { + painter->setPen(selected ? StyleHelper::panelTextColor() : QColor(255, 255, 255, 120)); + } + +#if defined(Q_OS_MAC) + bool isMac=true; +#else + bool isMac = false; +#endif + + // hover + if(!isMac && !selected && enabled) + { + painter->save(); + int fader = int(mAttachedTabs[tabIndex]->fader()); + QLinearGradient grad(getCorner(rect, OutsideBeginning), getCorner(rect, InsideBeginning)); + + grad.setColorAt(0, Qt::transparent); + grad.setColorAt(0.5, QColor(255, 255, 255, fader)); + grad.setColorAt(1, Qt::transparent); + painter->fillRect(rect, grad); + painter->setPen(QPen(grad, 1.0)); + + if(mPosition == Above || mPosition == Below) + { + painter->drawLine(rect.topLeft(), rect.bottomLeft()); + painter->drawLine(rect.topRight(), rect.bottomRight()); + } + else + { + painter->drawLine(rect.topLeft(), rect.topRight()); + painter->drawLine(rect.bottomLeft(), rect.bottomRight()); + } + + painter->restore(); + } + + if (!enabled) + painter->setOpacity(0.7); + + if (drawIcon) { + int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height(); + tabIconRect.adjust(0, 4, 0, -textHeight); + StyleHelper::drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, enabled ? QIcon::Normal : QIcon::Disabled); + } + + painter->translate(0, -1); + painter->drawText(tabTextRect, textFlags, tabText); + painter->restore(); +} + +void FancyTabBar2::setCurrentIndex(int index) { + if (isTabEnabled(index)) { + mCurrentIndex = index; + update(); + emit currentChanged(mCurrentIndex); + } +} + +void FancyTabBar2::setTabEnabled(int index, bool enable) +{ + Q_ASSERT(index < mAttachedTabs.size()); + Q_ASSERT(index >= 0); + + if (index < mAttachedTabs.size() && index >= 0) { + mAttachedTabs[index]->enabled = enable; + update(tabRect(index)); + } +} + +bool FancyTabBar2::isTabEnabled(int index) const +{ + Q_ASSERT(index < mAttachedTabs.size()); + Q_ASSERT(index >= 0); + + if (index < mAttachedTabs.size() && index >= 0) + return mAttachedTabs[index]->enabled; + + return false; +} diff --git a/BASuite/utils/fancytabbar.h b/BASuite/utils/fancytabbar.h new file mode 100644 index 0000000000000000000000000000000000000000..6f0fd865b2ba4e9384109907f9934d5c76c9f10c --- /dev/null +++ b/BASuite/utils/fancytabbar.h @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef FANCYTABBAR_H +#define FANCYTABBAR_H + +#include <QIcon> +#include <QWidget> + +#include <QTimer> +#include <QPropertyAnimation> + +class QPainter; + +#include "fancytab.h" + + + +class FancyTabBar : public QWidget +{ + Q_OBJECT + +public: + FancyTabBar(QWidget *parent = 0); + ~FancyTabBar(); + + bool event(QEvent *event); + + void paintEvent(QPaintEvent *event); + void paintTab(QPainter *painter, int tabIndex) const; + void mousePressEvent(QMouseEvent *); + void mouseMoveEvent(QMouseEvent *); + void enterEvent(QEvent *); + void leaveEvent(QEvent *); + bool validIndex(int index) const { return index >= 0 && index < m_tabs.count(); } + + QSize sizeHint() const; + QSize minimumSizeHint() const; + + void setTabEnabled(int index, bool enable); + bool isTabEnabled(int index) const; + + void insertTab(int index, const QIcon &icon, const QString &label) { + FancyTab *tab = new FancyTab(this); + tab->icon = icon; + tab->text = label; + m_tabs.insert(index, tab); + } + void setEnabled(int index, bool enabled); + void removeTab(int index) { + FancyTab *tab = m_tabs.takeAt(index); + delete tab; + } + void setCurrentIndex(int index); + int currentIndex() const { return m_currentIndex; } + + void setTabToolTip(int index, QString toolTip) { m_tabs[index]->toolTip = toolTip; } + QString tabToolTip(int index) const { return m_tabs.at(index)->toolTip; } + + QIcon tabIcon(int index) const { return m_tabs.at(index)->icon; } + QString tabText(int index) const { return m_tabs.at(index)->text; } + int count() const {return m_tabs.count(); } + QRect tabRect(int index) const; + +signals: + void currentChanged(int); + +public slots: + void emitCurrentIndex(); + +private: + static const int m_rounding; + static const int m_textPadding; + QRect m_hoverRect; + int m_hoverIndex; + int m_currentIndex; + QList<FancyTab*> m_tabs; + QTimer m_triggerTimer; + QSize tabSizeHint(bool minimum = false) const; + +}; + + + +class FancyTabBar2 : public QWidget +{ + Q_OBJECT + +public: +// enum struct TabBarPosition { Above, Below, Left, Right }; +// struct TabBarPosition { +// enum keys {Above, Below, Left, Right }; +// }; + enum TabBarPosition { Above, Below, Left, Right }; + + FancyTabBar2(QWidget *parent = 0, TabBarPosition position=Left ); + ~FancyTabBar2(); + + + bool event(QEvent *event); + + void paintEvent(QPaintEvent *event); + void paintTab(QPainter *painter, int tabIndex) const; + void mousePressEvent(QMouseEvent *); + void mouseMoveEvent(QMouseEvent *); + void enterEvent(QEvent *); + void leaveEvent(QEvent *); + bool validIndex(int index) const { return index >= 0 && index < mAttachedTabs.count(); } + + void setOrientation(const TabBarPosition p) {mPosition = p;} + QSize sizeHint() const; + QSize minimumSizeHint() const; + + void setTabEnabled(int index, bool enable); + bool isTabEnabled(int index) const; + + void insertTab(int index, const QIcon &icon, const QString &label) { + FancyTab *tab = new FancyTab(this); + tab->icon = icon; + tab->text = label; + mAttachedTabs.insert(index, tab); + } + + void removeTab(int index) { + FancyTab *tab = mAttachedTabs.takeAt(index); + delete tab; + } + void setCurrentIndex(int index); + int currentIndex() const { return mCurrentIndex; } + + void setTabToolTip(int index, QString toolTip) { mAttachedTabs[index]->toolTip = toolTip; } + QString tabToolTip(int index) const { return mAttachedTabs.at(index)->toolTip; } + + QIcon tabIcon(int index) const { return mAttachedTabs.at(index)->icon; } + QString tabText(int index) const { return mAttachedTabs.at(index)->text; } + int count() const {return mAttachedTabs.count(); } + QRect tabRect(int index) const; + +signals: + void currentChanged(int); + +public slots: + void emitCurrentIndex(); + +private: + //enum struct Corner { OutsideBeginning, OutsideEnd, InsideBeginning, InsideEnd }; + enum Corner { OutsideBeginning, OutsideEnd, InsideBeginning, InsideEnd }; + QPoint getCorner(const QRect& rect, const Corner corner) const; + + // You can pass this method a QRect and tell it to move its edges to the outside (+) + // or inside (-) of the rect. For example, with a TabBar at the Above, + // + // adjustRect(QRect(0,0,10,10), 1, 2, 3, -4) // thats a 10 by 10 QRect, starting at 0/0 + // + // gives + // + // QRect(-3, -1, 9, 13) // 9 by 13 rect, starting at -3/-1. + QRect adjustRect(const QRect& rect, const qint8 offsetOutside, const qint8 offsetInside, const qint8 offsetStart, const qint8 offsetEnd) const; + + // Same with a point. + means towards Outside/End, - means towards Inside/Beginning + QPoint adjustPoint(const QPoint& point, const qint8 offsetInsideOutside, const qint8 offsetBeginningEnd) const; + + TabBarPosition mPosition; + static const int m_rounding; + static const int m_textPadding; + QRect mHoverRect; + int mHoverIndex; + int mCurrentIndex; + QList<FancyTab*> mAttachedTabs; + QTimer mTimerTriggerChangedSignal; + QSize tabSizeHint(bool minimum = false) const; + +}; + +#endif // FANCYTABWIDGET_H diff --git a/BASuite/utils/stylehelper.cpp b/BASuite/utils/stylehelper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1a2a563e4b99ccff26962a074cdbea2fff11cae8 --- /dev/null +++ b/BASuite/utils/stylehelper.cpp @@ -0,0 +1,647 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + + + +#include "stylehelper.h" + +#include <QPixmapCache> +#include <QWidget> +#include <QRect> +#include <QPainter> +#include <QApplication> +#include <QPalette> +#include <QStyleOption> +#include <QObject> + +// Clamps float color values within (0, 255) +static int clamp(float x) +{ + const int val = x > 255 ? 255 : static_cast<int>(x); + return val < 0 ? 0 : val; +} + +// Clamps float color values within (0, 255) +/* +static int range(float x, int min, int max) +{ + int val = x > max ? max : x; + return val < min ? min : val; +} +*/ + +QColor StyleHelper::mergedColors(const QColor &colorA, const QColor &colorB, int factor) +{ + const int maxFactor = 100; + QColor tmp = colorA; + tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor); + tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor); + tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor); + return tmp; +} + +qreal StyleHelper::sidebarFontSize() +{ +#if defined(Q_OS_MAC) + return 10; +#else + return 7.5; +#endif +} + +QPalette StyleHelper::sidebarFontPalette(const QPalette &original) +{ + QPalette palette = original; + palette.setColor(QPalette::Active, QPalette::Text, panelTextColor()); + palette.setColor(QPalette::Active, QPalette::WindowText, panelTextColor()); + palette.setColor(QPalette::Inactive, QPalette::Text, panelTextColor().darker()); + palette.setColor(QPalette::Inactive, QPalette::WindowText, panelTextColor().darker()); + return palette; +} + +QColor StyleHelper::panelTextColor(bool lightColored) +{ + //qApp->palette().highlightedText().color(); + if (!lightColored) + return Qt::white; + else + return Qt::black; +} + +// Invalid by default, setBaseColor needs to be called at least once +QColor StyleHelper::m_baseColor; +QColor StyleHelper::m_requestedBaseColor; + +QColor StyleHelper::baseColor(bool lightColored) +{ + if (!lightColored) + return m_baseColor; + else + return m_baseColor.lighter(230); +} + +QColor StyleHelper::highlightColor(bool lightColored) +{ + QColor result = baseColor(lightColored); + if (!lightColored) + result.setHsv(result.hue(), + clamp(result.saturation()), + clamp(result.value() * 1.16)); + else + result.setHsv(result.hue(), + clamp(result.saturation()), + clamp(result.value() * 1.06)); + return result; +} + +QColor StyleHelper::shadowColor(bool lightColored) +{ + QColor result = baseColor(lightColored); + result.setHsv(result.hue(), + clamp(result.saturation() * 1.1), + clamp(result.value() * 0.70)); + return result; +} + +QColor StyleHelper::borderColor(bool lightColored) +{ + QColor result = baseColor(lightColored); + result.setHsv(result.hue(), + result.saturation(), + result.value() / 2); + return result; +} + +// We try to ensure that the actual color used are within +// reasonalbe bounds while generating the actual baseColor +// from the users request. +void StyleHelper::setBaseColor(const QColor &newcolor) +{ + m_requestedBaseColor = newcolor; + + QColor color; + color.setHsv(newcolor.hue(), + newcolor.saturation() * 0.7, + 64 + newcolor.value() / 3); + + if (color.isValid() && color != m_baseColor) { + m_baseColor = color; + foreach (QWidget *w, QApplication::topLevelWidgets()) + w->update(); + } +} + +static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRect &rect, bool lightColored) +{ + QColor highlight = StyleHelper::highlightColor(lightColored); + QColor shadow = StyleHelper::shadowColor(lightColored); + QLinearGradient grad(spanRect.topRight(), spanRect.topLeft()); + grad.setColorAt(0, highlight.lighter(117)); + grad.setColorAt(1, shadow.darker(109)); + p->fillRect(rect, grad); + + QColor light(255, 255, 255, 80); + p->setPen(light); + p->drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0)); + QColor dark(0, 0, 0, 90); + p->setPen(dark); + p->drawLine(rect.topLeft(), rect.bottomLeft()); +} + +void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored) +{ + if (StyleHelper::usePixmapCache()) { + QString key; + QColor keyColor = baseColor(lightColored); + key.sprintf("mh_vertical %d %d %d %d %d", + spanRect.width(), spanRect.height(), clipRect.width(), + clipRect.height(), keyColor.rgb());; + + QPixmap pixmap; + if (!QPixmapCache::find(key, pixmap)) { + pixmap = QPixmap(clipRect.size()); + QPainter p(&pixmap); + QRect rect(0, 0, clipRect.width(), clipRect.height()); + verticalGradientHelper(&p, spanRect, rect, lightColored); + p.end(); + QPixmapCache::insert(key, pixmap); + } + + painter->drawPixmap(clipRect.topLeft(), pixmap); + } else { + verticalGradientHelper(painter, spanRect, clipRect, lightColored); + } +} + +static void horizontalGradientHelper(QPainter *p, const QRect &spanRect, const +QRect &rect, bool lightColored) +{ + if (lightColored) { + QLinearGradient shadowGradient(rect.topLeft(), rect.bottomLeft()); + shadowGradient.setColorAt(0, 0xf0f0f0); + shadowGradient.setColorAt(1, 0xcfcfcf); + p->fillRect(rect, shadowGradient); + return; + } + + QColor base = StyleHelper::baseColor(lightColored); + QColor highlight = StyleHelper::highlightColor(lightColored); + QColor shadow = StyleHelper::shadowColor(lightColored); + QLinearGradient grad(rect.topLeft(), rect.bottomLeft()); + grad.setColorAt(0, highlight.lighter(120)); + if (rect.height() == StyleHelper::navigationWidgetHeight()) { + grad.setColorAt(0.4, highlight); + grad.setColorAt(0.401, base); + } + grad.setColorAt(1, shadow); + p->fillRect(rect, grad); + + QLinearGradient shadowGradient(spanRect.topLeft(), spanRect.topRight()); + shadowGradient.setColorAt(0, QColor(0, 0, 0, 30)); + QColor lighterHighlight; + lighterHighlight = highlight.lighter(130); + lighterHighlight.setAlpha(100); + shadowGradient.setColorAt(0.7, lighterHighlight); + shadowGradient.setColorAt(1, QColor(0, 0, 0, 40)); + p->fillRect(rect, shadowGradient); +} + +void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored) +{ + if (StyleHelper::usePixmapCache()) { + QString key; + QColor keyColor = baseColor(lightColored); + key.sprintf("mh_horizontal %d %d %d %d %d %d", + spanRect.width(), spanRect.height(), clipRect.width(), + clipRect.height(), keyColor.rgb(), spanRect.x()); + + QPixmap pixmap; + if (!QPixmapCache::find(key, pixmap)) { + pixmap = QPixmap(clipRect.size()); + QPainter p(&pixmap); + QRect rect = QRect(0, 0, clipRect.width(), clipRect.height()); + horizontalGradientHelper(&p, spanRect, rect, lightColored); + p.end(); + QPixmapCache::insert(key, pixmap); + } + + painter->drawPixmap(clipRect.topLeft(), pixmap); + + } else { + horizontalGradientHelper(painter, spanRect, clipRect, lightColored); + } +} + +static void menuGradientHelper(QPainter *p, const QRect &spanRect, const QRect &rect) +{ + QLinearGradient grad(spanRect.topLeft(), spanRect.bottomLeft()); + QColor menuColor = StyleHelper::mergedColors(StyleHelper::baseColor(), QColor(244, 244, 244), 25); + grad.setColorAt(0, menuColor.lighter(112)); + grad.setColorAt(1, menuColor); + p->fillRect(rect, grad); +} + +void StyleHelper::drawArrow(QStyle::PrimitiveElement element, QPainter *painter, const QStyleOption *option) +{ + // From windowsstyle but modified to enable AA + if (option->rect.width() <= 1 || option->rect.height() <= 1) + return; + + QRect r = option->rect; + int size = qMin(r.height(), r.width()); + QPixmap pixmap; + QString pixmapName; + pixmapName.sprintf("arrow-%s-%d-%d-%d-%lld", + "$qt_ia", + uint(option->state), element, + size, option->palette.cacheKey()); + if (!QPixmapCache::find(pixmapName, pixmap)) { + int border = size/5; + int sqsize = 2*(size/2); + QImage image(sqsize, sqsize, QImage::Format_ARGB32); + image.fill(Qt::transparent); + QPainter imagePainter(&image); + imagePainter.setRenderHint(QPainter::Antialiasing, true); + imagePainter.translate(0.5, 0.5); + QPolygon a; + switch (element) { + case QStyle::PE_IndicatorArrowUp: + a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2); + break; + case QStyle::PE_IndicatorArrowDown: + a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2); + break; + case QStyle::PE_IndicatorArrowRight: + a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); + break; + case QStyle::PE_IndicatorArrowLeft: + a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); + break; + default: + break; + } + + int bsx = 0; + int bsy = 0; + + if (option->state & QStyle::State_Sunken) { + bsx = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal); + bsy = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftVertical); + } + + QRect bounds = a.boundingRect(); + int sx = sqsize / 2 - bounds.center().x() - 1; + int sy = sqsize / 2 - bounds.center().y() - 1; + imagePainter.translate(sx + bsx, sy + bsy); + + if (!(option->state & QStyle::State_Enabled)) { + QColor foreGround(150, 150, 150, 150); + imagePainter.setBrush(option->palette.mid().color()); + imagePainter.setPen(option->palette.mid().color()); + } else { + QColor shadow(0, 0, 0, 100); + imagePainter.translate(0, 1); + imagePainter.setPen(shadow); + imagePainter.setBrush(shadow); + QColor foreGround(255, 255, 255, 210); + imagePainter.drawPolygon(a); + imagePainter.translate(0, -1); + imagePainter.setPen(foreGround); + imagePainter.setBrush(foreGround); + } + imagePainter.drawPolygon(a); + imagePainter.end(); + pixmap = QPixmap::fromImage(image); + QPixmapCache::insert(pixmapName, pixmap); + } + int xOffset = r.x() + (r.width() - size)/2; + int yOffset = r.y() + (r.height() - size)/2; + painter->drawPixmap(xOffset, yOffset, pixmap); +} + +void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect) +{ + if (StyleHelper::usePixmapCache()) { + QString key; + key.sprintf("mh_menu %d %d %d %d %d", + spanRect.width(), spanRect.height(), clipRect.width(), + clipRect.height(), StyleHelper::baseColor().rgb()); + + QPixmap pixmap; + if (!QPixmapCache::find(key, pixmap)) { + pixmap = QPixmap(clipRect.size()); + QPainter p(&pixmap); + QRect rect = QRect(0, 0, clipRect.width(), clipRect.height()); + menuGradientHelper(&p, spanRect, rect); + p.end(); + QPixmapCache::insert(key, pixmap); + } + + painter->drawPixmap(clipRect.topLeft(), pixmap); + } else { + menuGradientHelper(painter, spanRect, clipRect); + } +} + +// Draws a cached pixmap with shadow +void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect, + QPainter *p, QIcon::Mode iconMode, int radius, const QColor &color, const QPoint &offset) +{ + QPixmap cache; + QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height()); + + if (!QPixmapCache::find(pixmapName, cache)) { + QPixmap px = icon.pixmap(rect.size()); + cache = QPixmap(px.size() + QSize(radius * 2, radius * 2)); + cache.fill(Qt::transparent); + + QPainter cachePainter(&cache); + if (iconMode == QIcon::Disabled) { + QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32); + for (int y=0; y<im.height(); ++y) { + QRgb *scanLine = (QRgb*)im.scanLine(y); + for (int x=0; x<im.width(); ++x) { + QRgb pixel = *scanLine; + char intensity = qGray(pixel); + *scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel)); + ++scanLine; + } + } + px = QPixmap::fromImage(im); + } + + // Draw shadow + QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied); + tmp.fill(Qt::transparent); + + QPainter tmpPainter(&tmp); + tmpPainter.setCompositionMode(QPainter::CompositionMode_Source); + tmpPainter.drawPixmap(QPoint(radius, radius), px); + tmpPainter.end(); + + // blur the alpha channel + QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied); + blurred.fill(Qt::transparent); + QPainter blurPainter(&blurred); + qt_blurImage(&blurPainter, tmp, radius, false, true); + blurPainter.end(); + + tmp = blurred; + + // blacken the image... + tmpPainter.begin(&tmp); + tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); + tmpPainter.fillRect(tmp.rect(), color); + tmpPainter.end(); + + tmpPainter.begin(&tmp); + tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); + tmpPainter.fillRect(tmp.rect(), color); + tmpPainter.end(); + + // draw the blurred drop shadow... + cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp); + + // Draw the actual pixmap... + cachePainter.drawPixmap(QPoint(radius, radius) + offset, px); + QPixmapCache::insert(pixmapName, cache); + } + + QRect targetRect = cache.rect(); + targetRect.moveCenter(rect.center()); + p->drawPixmap(targetRect.topLeft() - offset, cache); +} + +// Draws a CSS-like border image where the defined borders are not stretched +void StyleHelper::drawCornerImage(const QImage &img, QPainter *painter, QRect rect, + int left, int top, int right, int bottom) +{ + QSize size = img.size(); + if (top > 0) { //top + painter->drawImage(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), img, + QRect(left, 0, size.width() -right - left, top)); + if (left > 0) //top-left + painter->drawImage(QRect(rect.left(), rect.top(), left, top), img, + QRect(0, 0, left, top)); + if (right > 0) //top-right + painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top(), right, top), img, + QRect(size.width() - right, 0, right, top)); + } + //left + if (left > 0) + painter->drawImage(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), img, + QRect(0, top, left, size.height() - bottom - top)); + //center + painter->drawImage(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left, + rect.height() - bottom - top), img, + QRect(left, top, size.width() -right -left, + size.height() - bottom - top)); + if (right > 0) //right + painter->drawImage(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), img, + QRect(size.width() - right, top, right, size.height() - bottom - top)); + if (bottom > 0) { //bottom + painter->drawImage(QRect(rect.left() +left, rect.top() + rect.height() - bottom, + rect.width() - right - left, bottom), img, + QRect(left, size.height() - bottom, + size.width() - right - left, bottom)); + if (left > 0) //bottom-left + painter->drawImage(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), img, + QRect(0, size.height() - bottom, left, bottom)); + if (right > 0) //bottom-right + painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), img, + QRect(size.width() - right, size.height() - bottom, right, bottom)); + } +} + +// Tints an image with tintColor, while preserving alpha and lightness +void StyleHelper::tintImage(QImage &img, const QColor &tintColor) +{ + QPainter p(&img); + p.setCompositionMode(QPainter::CompositionMode_Screen); + + for (int x = 0; x < img.width(); ++x) { + for (int y = 0; y < img.height(); ++y) { + QRgb rgbColor = img.pixel(x, y); + int alpha = qAlpha(rgbColor); + QColor c = QColor(rgbColor); + + if (alpha > 0) { + c.toHsl(); + qreal l = c.lightnessF(); + QColor newColor = QColor::fromHslF(tintColor.hslHueF(), tintColor.hslSaturationF(), l); + newColor.setAlpha(alpha); + img.setPixel(x, y, newColor.rgba()); + } + } + } +} + + + + + + +//#include "stylehelper.h" + +//#include <QPixmapCache> +//#include <QWidget> +//#include <QRect> +//#include <QPainter> +//#include <QApplication> +//#include <QPalette> +//#include <QStyleOption> +//#include <QObject> + +//qreal StyleHelper::sidebarFontSize() +//{ +//#if defined(Q_OS_MAC) +// return 10; +//#else +// return 7.5; +//#endif +//} + +//QColor StyleHelper::panelTextColor(bool lightColored) +//{ +// //qApp->palette().highlightedText().color(); +// if (!lightColored) +// return Qt::white; +// else +// return Qt::black; +//} + +//// Invalid by default, setBaseColor needs to be called at least once +//QColor StyleHelper::m_baseColor; +//QColor StyleHelper::m_requestedBaseColor; + +//QColor StyleHelper::baseColor(bool lightColored) +//{ +// if (!lightColored) +// return m_baseColor; +// else +// return m_baseColor.lighter(230); +//} + +//QColor StyleHelper::borderColor(bool lightColored) +//{ +// QColor result = baseColor(lightColored); +// result.setHsv(result.hue(), +// result.saturation(), +// result.value() / 2); +// return result; +//} + +//// We try to ensure that the actual color used are within +//// reasonalbe bounds while generating the actual baseColor +//// from the users request. +//void StyleHelper::setBaseColor(const QColor &newcolor) +//{ +// m_requestedBaseColor = newcolor; + +// QColor color; +// color.setHsv(newcolor.hue(), +// newcolor.saturation() * 0.7, +// 64 + newcolor.value() / 3); + +// if (color.isValid() && color != m_baseColor) { +// m_baseColor = color; +// foreach (QWidget *w, QApplication::topLevelWidgets()) +// w->update(); +// } +//} + + +//// Draws a cached pixmap with shadow +//void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect, +// QPainter *p, QIcon::Mode iconMode, int radius, const QColor &color, const QPoint &offset) +//{ +// QPixmap cache; +// QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height()); + +// if (!QPixmapCache::find(pixmapName, cache)) { +// QPixmap px = icon.pixmap(rect.size()); +// cache = QPixmap(px.size() + QSize(radius * 2, radius * 2)); +// cache.fill(Qt::transparent); + +// QPainter cachePainter(&cache); +// if (iconMode == QIcon::Disabled) { +// QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32); +// for (int y=0; y<im.height(); ++y) { +// QRgb *scanLine = (QRgb*)im.scanLine(y); +// for (int x=0; x<im.width(); ++x) { +// QRgb pixel = *scanLine; +// char intensity = qGray(pixel); +// *scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel)); +// ++scanLine; +// } +// } +// px = QPixmap::fromImage(im); +// } + +// // Draw shadow +// QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied); +// tmp.fill(Qt::transparent); + +// QPainter tmpPainter(&tmp); +// tmpPainter.setCompositionMode(QPainter::CompositionMode_Source); +// tmpPainter.drawPixmap(QPoint(radius, radius), px); +// tmpPainter.end(); + +// // blur the alpha channel +// QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied); +// blurred.fill(Qt::transparent); +// QPainter blurPainter(&blurred); +// qt_blurImage(&blurPainter, tmp, radius, false, true); +// blurPainter.end(); + +// tmp = blurred; + +// // blacken the image... +// tmpPainter.begin(&tmp); +// tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); +// tmpPainter.fillRect(tmp.rect(), color); +// tmpPainter.end(); + +// tmpPainter.begin(&tmp); +// tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); +// tmpPainter.fillRect(tmp.rect(), color); +// tmpPainter.end(); + +// // draw the blurred drop shadow... +// cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp); + +// // Draw the actual pixmap... +// cachePainter.drawPixmap(QPoint(radius, radius) + offset, px); +// QPixmapCache::insert(pixmapName, cache); +// } + +// QRect targetRect = cache.rect(); +// targetRect.moveCenter(rect.center()); +// p->drawPixmap(targetRect.topLeft() - offset, cache); +//} diff --git a/BASuite/utils/stylehelper.h b/BASuite/utils/stylehelper.h new file mode 100644 index 0000000000000000000000000000000000000000..7db6f8a1ea88359f770945e37a2b68dc7a0d0b96 --- /dev/null +++ b/BASuite/utils/stylehelper.h @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef STYLEHELPER_H +#define STYLEHELPER_H + + +#include <QColor> +#include <QStyle> + +class QPalette; +class QPainter; +class QRect; +void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0); + +class StyleHelper +{ +public: + static const unsigned int DEFAULT_BASE_COLOR = 0x666666; + + // Height of the project explorer navigation bar + static int navigationWidgetHeight() { return 24; } + static qreal sidebarFontSize(); + static QPalette sidebarFontPalette(const QPalette &original); + + // This is our color table, all colors derive from baseColor + static QColor requestedBaseColor() { return m_requestedBaseColor; } + static QColor baseColor(bool lightColored = false); + static QColor panelTextColor(bool lightColored = false); + static QColor highlightColor(bool lightColored = false); + static QColor shadowColor(bool lightColored = false); + static QColor borderColor(bool lightColored = false); + static QColor buttonTextColor() { return QColor(0x4c4c4c); } + static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50); + + static QColor sidebarHighlight() { return QColor(255, 255, 255, 40); } + static QColor sidebarShadow() { return QColor(0, 0, 0, 40); } + + // Sets the base color and makes sure all top level widgets are updated + static void setBaseColor(const QColor &color); + + // Draws a shaded anti-aliased arrow + static void drawArrow(QStyle::PrimitiveElement element, QPainter *painter, const QStyleOption *option); + + // Gradients used for panels + static void horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored = false); + static void verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored = false); + static void menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect); + static bool usePixmapCache() { return true; } + + static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, + int radius = 3, const QColor &color = QColor(0, 0, 0, 130), + const QPoint &offset = QPoint(1, -2)); + static void drawCornerImage(const QImage &img, QPainter *painter, QRect rect, + int left = 0, int top = 0, int right = 0, int bottom = 0); + + static void tintImage(QImage &img, const QColor &tintColor); + +private: + static QColor m_baseColor; + static QColor m_requestedBaseColor; +}; + + + + + +//#include <QColor> +//#include <QStyle> + +//class QPalette; +//class QPainter; +//class QRect; + +//// Note, this is exported but in a private header as qtopengl depends on it. +//// We should consider adding this as a public helper function. +//void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0); + +//// Helper class holding all custom color values +//class StyleHelper +//{ +//public: +// static const unsigned int DEFAULT_BASE_COLOR = 0x666666; + +// static qreal sidebarFontSize(); +// // This is our color table, all colors derive from baseColor +// static QColor baseColor(bool lightColored = false); +// static QColor panelTextColor(bool lightColored = false); +// static QColor borderColor(bool lightColored = false); +// static QColor sidebarHighlight() { return QColor(255, 255, 255, 40); } + +// // Sets the base color and makes sure all top level widgets are updated +// static void setBaseColor(const QColor &color); +// static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, int radius = 3, const QColor &color = QColor(0, 0, 0, 130), const QPoint &offset = QPoint(1, -2)); + +// static QColor requestedBaseColor() { return m_requestedBaseColor; } +//private: +// static QColor m_baseColor; +// static QColor m_requestedBaseColor; +//}; + +#endif // STYLEHELPER_H diff --git a/BASuite/welcomemanager/welcomemanager.cpp b/BASuite/welcomemanager/welcomemanager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f7c7315f9279aba63d6cec5a31969ba24104f90f --- /dev/null +++ b/BASuite/welcomemanager/welcomemanager.cpp @@ -0,0 +1,30 @@ +#include "welcomemanager.h" +#include <QtWidgets> + +WelcomeManager::WelcomeManager(QWidget *parent) + : QWidget(parent) +{ + QGroupBox *configGroup = new QGroupBox(tr("Server configuration")); + + QLabel *serverLabel = new QLabel(tr("Server:")); + QComboBox *serverCombo = new QComboBox; + serverCombo->addItem(tr("Qt (Australia)")); + serverCombo->addItem(tr("Qt (Germany)")); + serverCombo->addItem(tr("Qt (Norway)")); + serverCombo->addItem(tr("Qt (People's Republic of China)")); + serverCombo->addItem(tr("Qt (USA)")); + + QHBoxLayout *serverLayout = new QHBoxLayout; + serverLayout->addWidget(serverLabel); + serverLayout->addWidget(serverCombo); + + QVBoxLayout *configLayout = new QVBoxLayout; + configLayout->addLayout(serverLayout); + configGroup->setLayout(configLayout); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(configGroup); + mainLayout->addStretch(1); + setLayout(mainLayout); +} + diff --git a/BASuite/welcomemanager/welcomemanager.h b/BASuite/welcomemanager/welcomemanager.h new file mode 100644 index 0000000000000000000000000000000000000000..1bf340e2be3fc287eca3791d46b5527843fefdd9 --- /dev/null +++ b/BASuite/welcomemanager/welcomemanager.h @@ -0,0 +1,13 @@ +#ifndef WELCOMEMANAGER_H +#define WELCOMEMANAGER_H + +#include <QWidget> + +class WelcomeManager : public QWidget +{ +public: + WelcomeManager(QWidget *parent = 0); + +}; + +#endif // WELCOMEMANAGER_H