Files
qt-creator/src/plugins/coreplugin/outputpanemanager.cpp

850 lines
28 KiB
C++
Raw Normal View History

/****************************************************************************
2010-09-16 12:26:28 +02:00
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
2010-09-16 12:26:28 +02:00
**
** This file is part of Qt Creator.
2010-09-16 12:26:28 +02:00
**
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
2010-09-16 12:26:28 +02:00
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
2010-12-17 16:01:08 +01:00
**
****************************************************************************/
2010-09-16 12:26:28 +02:00
#include "outputpanemanager.h"
#include "outputpane.h"
#include "coreicons.h"
2010-09-16 12:26:28 +02:00
#include "findplaceholder.h"
#include "icore.h"
#include "ioutputpane.h"
#include "modemanager.h"
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
2010-09-16 12:26:28 +02:00
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/hostosinfo.h>
2010-09-16 12:26:28 +02:00
#include <utils/styledbar.h>
#include <utils/stylehelper.h>
#include <utils/proxyaction.h>
2010-09-16 12:26:28 +02:00
#include <utils/qtcassert.h>
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
#include <utils/theme/theme.h>
#include <utils/utilsicons.h>
2010-09-16 12:26:28 +02:00
#include <QDebug>
2010-09-16 12:26:28 +02:00
#include <QAction>
#include <QApplication>
#include <QComboBox>
#include <QFocusEvent>
#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QPainter>
#include <QStyle>
#include <QStackedWidget>
#include <QToolButton>
#include <QTimeLine>
2010-09-16 12:26:28 +02:00
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
using namespace Utils;
2010-09-16 12:26:28 +02:00
namespace Core {
namespace Internal {
static char outputPaneSettingsKeyC[] = "OutputPaneVisibility";
static char outputPaneIdKeyC[] = "id";
static char outputPaneVisibleKeyC[] = "visible";
static const int buttonBorderWidth = 3;
static int numberAreaWidth()
{
return creatorTheme()->widgetStyle() == Theme::StyleDefault ? 19 : 15;
}
2010-09-16 12:26:28 +02:00
////
// OutputPaneManager
////
static OutputPaneManager *m_instance = 0;
void OutputPaneManager::create()
{
m_instance = new OutputPaneManager;
}
void OutputPaneManager::destroy()
{
delete m_instance;
m_instance = 0;
}
OutputPaneManager *OutputPaneManager::instance()
{
return m_instance;
}
void OutputPaneManager::updateStatusButtons(bool visible)
{
int idx = currentIndex();
if (idx == -1)
return;
QTC_ASSERT(m_panes.size() == m_buttons.size(), return);
m_buttons.at(idx)->setChecked(visible);
m_panes.at(idx)->visibilityChanged(visible);
}
void OutputPaneManager::updateMaximizeButton(bool maximized)
{
if (maximized) {
m_instance->m_minMaxAction->setIcon(m_instance->m_minimizeIcon);
m_instance->m_minMaxAction->setText(tr("Minimize Output Pane"));
} else {
m_instance->m_minMaxAction->setIcon(m_instance->m_maximizeIcon);
m_instance->m_minMaxAction->setText(tr("Maximize Output Pane"));
}
2010-09-16 12:26:28 +02:00
}
OutputPaneManager::OutputPaneManager(QWidget *parent) :
QWidget(parent),
m_titleLabel(new QLabel),
m_manageButton(new OutputPaneManageButton),
2010-09-16 12:26:28 +02:00
m_closeButton(new QToolButton),
m_minMaxAction(0),
m_minMaxButton(new QToolButton),
m_nextAction(0),
m_prevAction(0),
m_outputWidgetPane(new QStackedWidget),
m_opToolBarWidgets(new QStackedWidget),
m_minimizeIcon(Icons::ARROW_DOWN.icon()),
m_maximizeIcon(Icons::ARROW_UP.icon()),
m_outputPaneHeightSetting(0)
2010-09-16 12:26:28 +02:00
{
setWindowTitle(tr("Output"));
m_titleLabel->setContentsMargins(5, 0, 5, 0);
2010-09-16 12:26:28 +02:00
m_clearAction = new QAction(this);
m_clearAction->setIcon(Icons::CLEAN.icon());
m_clearAction->setText(tr("Clear"));
connect(m_clearAction, &QAction::triggered, this, &OutputPaneManager::clearPage);
2010-09-16 12:26:28 +02:00
m_nextAction = new QAction(this);
m_nextAction->setIcon(Utils::Icons::NEXT.icon());
2010-09-16 12:26:28 +02:00
m_nextAction->setText(tr("Next Item"));
connect(m_nextAction, &QAction::triggered, this, &OutputPaneManager::slotNext);
2010-09-16 12:26:28 +02:00
m_prevAction = new QAction(this);
m_prevAction->setIcon(Utils::Icons::PREV.icon());
2010-09-16 12:26:28 +02:00
m_prevAction->setText(tr("Previous Item"));
connect(m_prevAction, &QAction::triggered, this, &OutputPaneManager::slotPrev);
2010-09-16 12:26:28 +02:00
m_minMaxAction = new QAction(this);
m_minMaxAction->setIcon(m_maximizeIcon);
m_minMaxAction->setText(tr("Maximize Output Pane"));
m_closeButton->setIcon(Icons::CLOSE_SPLIT_BOTTOM.icon());
connect(m_closeButton, &QAbstractButton::clicked, this, &OutputPaneManager::slotHide);
2010-09-16 12:26:28 +02:00
connect(ICore::instance(), &ICore::saveSettingsRequested, this, &OutputPaneManager::saveSettings);
2010-09-16 12:26:28 +02:00
QVBoxLayout *mainlayout = new QVBoxLayout;
mainlayout->setSpacing(0);
mainlayout->setMargin(0);
m_toolBar = new StyledBar;
2010-09-16 12:26:28 +02:00
QHBoxLayout *toolLayout = new QHBoxLayout(m_toolBar);
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
toolLayout->addWidget(m_titleLabel);
toolLayout->addWidget(new StyledSeparator);
m_clearButton = new QToolButton;
2010-09-16 12:26:28 +02:00
toolLayout->addWidget(m_clearButton);
m_prevToolButton = new QToolButton;
toolLayout->addWidget(m_prevToolButton);
m_nextToolButton = new QToolButton;
toolLayout->addWidget(m_nextToolButton);
toolLayout->addWidget(m_opToolBarWidgets);
toolLayout->addWidget(m_minMaxButton);
toolLayout->addWidget(m_closeButton);
mainlayout->addWidget(m_toolBar);
mainlayout->addWidget(m_outputWidgetPane, 10);
mainlayout->addWidget(new FindToolBarPlaceHolder(this));
2010-09-16 12:26:28 +02:00
setLayout(mainlayout);
m_buttonsWidget = new QWidget;
m_buttonsWidget->setLayout(new QHBoxLayout);
m_buttonsWidget->layout()->setContentsMargins(5,0,0,0);
m_buttonsWidget->layout()->setSpacing(
creatorTheme()->widgetStyle() == Theme::StyleDefault ? 4 : 9);
2010-09-16 12:26:28 +02:00
}
OutputPaneManager::~OutputPaneManager()
{
}
QWidget *OutputPaneManager::buttonsWidget()
{
return m_buttonsWidget;
}
// Return shortcut as Alt+<number> or Cmd+<number> if number is a non-zero digit
static inline QKeySequence paneShortCut(int number)
2010-09-16 12:26:28 +02:00
{
if (number < 1 || number > 9)
return QKeySequence();
const int modifier = HostOsInfo::isMacHost() ? Qt::CTRL : Qt::ALT;
return QKeySequence(modifier | (Qt::Key_0 + number));
2010-09-16 12:26:28 +02:00
}
void OutputPaneManager::init()
{
ActionContainer *mwindow = ActionManager::actionContainer(Constants::M_WINDOW);
2010-09-16 12:26:28 +02:00
// Window->Output Panes
ActionContainer *mpanes = ActionManager::createMenu(Constants::M_WINDOW_PANES);
2010-09-16 12:26:28 +02:00
mwindow->addMenu(mpanes, Constants::G_WINDOW_PANES);
mpanes->menu()->setTitle(tr("Output &Panes"));
mpanes->appendGroup("Coreplugin.OutputPane.ActionsGroup");
mpanes->appendGroup("Coreplugin.OutputPane.PanesGroup");
Command *cmd;
2010-09-16 12:26:28 +02:00
cmd = ActionManager::registerAction(m_clearAction, "Coreplugin.OutputPane.clear");
m_clearButton->setDefaultAction(cmd->action());
m_clearButton->setIcon(Icons::CLEAN_TOOLBAR.icon());
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
cmd = ActionManager::registerAction(m_prevAction, "Coreplugin.OutputPane.previtem");
cmd->setDefaultKeySequence(QKeySequence(tr("Shift+F6")));
m_prevToolButton->setDefaultAction(
ProxyAction::proxyActionWithIcon(cmd->action(), Utils::Icons::PREV_TOOLBAR.icon()));
2010-09-16 12:26:28 +02:00
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
cmd = ActionManager::registerAction(m_nextAction, "Coreplugin.OutputPane.nextitem");
m_nextToolButton->setDefaultAction(
ProxyAction::proxyActionWithIcon(cmd->action(), Utils::Icons::NEXT_TOOLBAR.icon()));
cmd->setDefaultKeySequence(QKeySequence(tr("F6")));
2010-09-16 12:26:28 +02:00
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
cmd = ActionManager::registerAction(m_minMaxAction, "Coreplugin.OutputPane.minmax");
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Ctrl+Shift+9") : tr("Alt+Shift+9")));
2010-09-16 12:26:28 +02:00
cmd->setAttribute(Command::CA_UpdateText);
cmd->setAttribute(Command::CA_UpdateIcon);
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
connect(m_minMaxAction, &QAction::triggered, this, &OutputPaneManager::toggleMaximized);
2010-09-16 12:26:28 +02:00
m_minMaxButton->setDefaultAction(cmd->action());
mpanes->addSeparator("Coreplugin.OutputPane.ActionsGroup");
2010-09-16 12:26:28 +02:00
QFontMetrics titleFm = m_titleLabel->fontMetrics();
int minTitleWidth = 0;
m_panes = ExtensionSystem::PluginManager::getObjects<IOutputPane>();
Utils::sort(m_panes, [](IOutputPane *p1, IOutputPane *p2) {
return p1->priorityInStatusBar() > p2->priorityInStatusBar();
});
const int n = m_panes.size();
2010-09-16 12:26:28 +02:00
int shortcutNumber = 1;
const Id baseId = "QtCreator.Pane.";
for (int i = 0; i != n; ++i) {
IOutputPane *outPane = m_panes.at(i);
2010-09-16 12:26:28 +02:00
const int idx = m_outputWidgetPane->addWidget(outPane->outputWidget(this));
QTC_CHECK(idx == i);
2010-09-16 12:26:28 +02:00
connect(outPane, &IOutputPane::showPage, this, [this, outPane](int flags) {
showPage(findIndexForPage(outPane), flags);
});
connect(outPane, &IOutputPane::hidePage, this, &OutputPaneManager::slotHide);
connect(outPane, &IOutputPane::togglePage, this, &OutputPaneManager::togglePage);
connect(outPane, &IOutputPane::navigateStateUpdate,
this, &OutputPaneManager::updateNavigateState);
connect(outPane, &IOutputPane::flashButton, this, &OutputPaneManager::flashButton);
connect(outPane, &IOutputPane::setBadgeNumber, this, &OutputPaneManager::setBadgeNumber);
2010-09-16 12:26:28 +02:00
QWidget *toolButtonsContainer = new QWidget(m_opToolBarWidgets);
QHBoxLayout *toolButtonsLayout = new QHBoxLayout;
toolButtonsLayout->setMargin(0);
toolButtonsLayout->setSpacing(0);
foreach (QWidget *toolButton, outPane->toolBarWidgets())
toolButtonsLayout->addWidget(toolButton);
toolButtonsLayout->addStretch(5);
toolButtonsContainer->setLayout(toolButtonsLayout);
m_opToolBarWidgets->addWidget(toolButtonsContainer);
minTitleWidth = qMax(minTitleWidth, titleFm.width(outPane->displayName()));
QString suffix = outPane->displayName().simplified();
suffix.remove(QLatin1Char(' '));
const Id id = baseId.withSuffix(suffix);
2010-09-16 12:26:28 +02:00
QAction *action = new QAction(outPane->displayName(), this);
Command *cmd = ActionManager::registerAction(action, id);
2010-09-16 12:26:28 +02:00
mpanes->addAction(cmd, "Coreplugin.OutputPane.PanesGroup");
m_actions.append(action);
m_ids.append(id);
2010-09-16 12:26:28 +02:00
cmd->setDefaultKeySequence(paneShortCut(shortcutNumber));
OutputPaneToggleButton *button = new OutputPaneToggleButton(shortcutNumber, outPane->displayName(),
cmd->action());
++shortcutNumber;
m_buttonsWidget->layout()->addWidget(button);
m_buttons.append(button);
connect(button, &QAbstractButton::clicked, this, [this, button]() {
buttonTriggered(m_buttons.indexOf(button));
});
bool visible = outPane->priorityInStatusBar() != -1;
button->setVisible(visible);
m_buttonVisibility.insert(id, visible);
2010-09-16 12:26:28 +02:00
connect(action, &QAction::triggered, this, &OutputPaneManager::shortcutTriggered);
}
2010-09-16 12:26:28 +02:00
m_titleLabel->setMinimumWidth(minTitleWidth + m_titleLabel->contentsMargins().left()
+ m_titleLabel->contentsMargins().right());
m_buttonsWidget->layout()->addWidget(m_manageButton);
connect(m_manageButton, &QAbstractButton::clicked, this, &OutputPaneManager::popupMenu);
readSettings();
2010-09-16 12:26:28 +02:00
}
void OutputPaneManager::shortcutTriggered()
{
QAction *action = qobject_cast<QAction*>(sender());
QTC_ASSERT(action, return);
int idx = m_actions.indexOf(action);
QTC_ASSERT(idx != -1, return);
IOutputPane *outputPane = m_panes.at(idx);
// Now check the special case, the output window is already visible,
// we are already on that page but the outputpane doesn't have focus
// then just give it focus.
int current = currentIndex();
if (OutputPanePlaceHolder::isCurrentVisible() && current == idx) {
if (!outputPane->hasFocus() && outputPane->canFocus()) {
outputPane->setFocus();
ICore::raiseWindow(m_outputWidgetPane);
} else {
slotHide();
}
} else {
// Else do the same as clicking on the button does.
buttonTriggered(idx);
2010-09-16 12:26:28 +02:00
}
}
int OutputPaneManager::outputPaneHeightSetting()
2010-09-16 12:26:28 +02:00
{
return m_instance->m_outputPaneHeightSetting;
2010-09-16 12:26:28 +02:00
}
void OutputPaneManager::setOutputPaneHeightSetting(int value)
{
m_instance->m_outputPaneHeightSetting = value;
}
void OutputPaneManager::toggleMaximized()
2010-09-16 12:26:28 +02:00
{
OutputPanePlaceHolder *ph = OutputPanePlaceHolder::getCurrent();
QTC_ASSERT(ph, return);
2010-09-16 12:26:28 +02:00
if (!ph->isVisible()) // easier than disabling/enabling the action
2010-09-16 12:26:28 +02:00
return;
ph->setMaximized(!ph->isMaximized());
2010-09-16 12:26:28 +02:00
}
void OutputPaneManager::buttonTriggered(int idx)
{
QTC_ASSERT(idx >= 0, return);
if (idx == currentIndex() && OutputPanePlaceHolder::isCurrentVisible()) {
2010-09-16 12:26:28 +02:00
// we should toggle and the page is already visible and we are actually closeable
slotHide();
} else {
showPage(idx, IOutputPane::ModeSwitch | IOutputPane::WithFocus);
2010-09-16 12:26:28 +02:00
}
}
void OutputPaneManager::readSettings()
{
QSettings *settings = ICore::settings();
int num = settings->beginReadArray(QLatin1String(outputPaneSettingsKeyC));
for (int i = 0; i < num; ++i) {
settings->setArrayIndex(i);
m_buttonVisibility.insert(Id::fromSetting(settings->value(QLatin1String(outputPaneIdKeyC))),
settings->value(QLatin1String(outputPaneVisibleKeyC)).toBool());
}
settings->endArray();
for (int i = 0; i < m_ids.size(); ++i) {
if (m_buttonVisibility.contains(m_ids.at(i)))
m_buttons.at(i)->setVisible(m_buttonVisibility.value(m_ids.at(i)));
}
m_outputPaneHeightSetting = settings->value(QLatin1String("OutputPanePlaceHolder/Height"), 0).toInt();
}
2010-09-16 12:26:28 +02:00
void OutputPaneManager::slotNext()
{
int idx = currentIndex();
2010-09-16 12:26:28 +02:00
ensurePageVisible(idx);
IOutputPane *out = m_panes.at(idx);
2010-09-16 12:26:28 +02:00
if (out->canNext())
out->goToNext();
}
void OutputPaneManager::slotPrev()
{
int idx = currentIndex();
2010-09-16 12:26:28 +02:00
ensurePageVisible(idx);
IOutputPane *out = m_panes.at(idx);
2010-09-16 12:26:28 +02:00
if (out->canPrevious())
out->goToPrev();
}
void OutputPaneManager::slotHide()
{
OutputPanePlaceHolder *ph = OutputPanePlaceHolder::getCurrent();
if (ph) {
ph->setVisible(false);
int idx = currentIndex();
QTC_ASSERT(idx >= 0, return);
m_buttons.at(idx)->setChecked(false);
m_panes.value(idx)->visibilityChanged(false);
if (IEditor *editor = EditorManager::currentEditor()) {
QWidget *w = editor->widget()->focusWidget();
if (!w)
w = editor->widget();
w->setFocus();
}
2010-09-16 12:26:28 +02:00
}
}
int OutputPaneManager::findIndexForPage(IOutputPane *out)
{
return m_panes.indexOf(out);
2010-09-16 12:26:28 +02:00
}
void OutputPaneManager::ensurePageVisible(int idx)
{
//int current = currentIndex();
//if (current != idx)
// m_outputWidgetPane->setCurrentIndex(idx);
setCurrentIndex(idx);
2010-09-16 12:26:28 +02:00
}
void OutputPaneManager::updateNavigateState()
{
IOutputPane *pane = qobject_cast<IOutputPane*>(sender());
2010-09-16 12:26:28 +02:00
int idx = findIndexForPage(pane);
if (currentIndex() == idx) {
2010-09-16 12:26:28 +02:00
m_prevAction->setEnabled(pane->canNavigate() && pane->canPrevious());
m_nextAction->setEnabled(pane->canNavigate() && pane->canNext());
}
}
void OutputPaneManager::flashButton()
{
IOutputPane* pane = qobject_cast<IOutputPane*>(sender());
int idx = findIndexForPage(pane);
if (pane)
m_buttons.value(idx)->flash();
}
void OutputPaneManager::setBadgeNumber(int number)
{
IOutputPane* pane = qobject_cast<IOutputPane*>(sender());
int idx = findIndexForPage(pane);
if (pane)
m_buttons.value(idx)->setIconBadgeNumber(number);
}
void OutputPaneManager::showPage(int idx, int flags)
2010-09-16 12:26:28 +02:00
{
QTC_ASSERT(idx >= 0, return);
OutputPanePlaceHolder *ph = OutputPanePlaceHolder::getCurrent();
if (!ph && flags & IOutputPane::ModeSwitch) {
// In this mode we don't have a placeholder
// switch to the output mode and switch the page
ModeManager::activateMode(Id(Constants::MODE_EDIT));
ph = OutputPanePlaceHolder::getCurrent();
}
bool onlyFlash = !ph
|| (m_panes.at(currentIndex())->hasFocus()
&& !(flags & IOutputPane::WithFocus)
&& idx != currentIndex());
if (onlyFlash) {
m_buttons.value(idx)->flash();
} else {
// make the page visible
ph->setVisible(true);
ensurePageVisible(idx);
IOutputPane *out = m_panes.at(idx);
out->visibilityChanged(true);
if (flags & IOutputPane::WithFocus) {
if (out->canFocus())
out->setFocus();
ICore::raiseWindow(m_outputWidgetPane);
}
if (flags & IOutputPane::EnsureSizeHint)
ph->ensureSizeHintAsMinimum();
2010-09-16 12:26:28 +02:00
}
}
void OutputPaneManager::togglePage(int flags)
2010-09-16 12:26:28 +02:00
{
int idx = findIndexForPage(qobject_cast<IOutputPane*>(sender()));
if (OutputPanePlaceHolder::isCurrentVisible() && currentIndex() == idx)
2010-09-16 12:26:28 +02:00
slotHide();
else
showPage(idx, flags);
2010-09-16 12:26:28 +02:00
}
void OutputPaneManager::focusInEvent(QFocusEvent *e)
{
if (QWidget *w = m_outputWidgetPane->currentWidget())
w->setFocus(e->reason());
2010-09-16 12:26:28 +02:00
}
void OutputPaneManager::setCurrentIndex(int idx)
2010-09-16 12:26:28 +02:00
{
static int lastIndex = -1;
2010-09-16 12:26:28 +02:00
if (lastIndex != -1) {
m_buttons.at(lastIndex)->setChecked(false);
m_panes.at(lastIndex)->visibilityChanged(false);
2010-09-16 12:26:28 +02:00
}
if (idx != -1) {
2010-09-16 12:26:28 +02:00
m_outputWidgetPane->setCurrentIndex(idx);
m_opToolBarWidgets->setCurrentIndex(idx);
IOutputPane *pane = m_panes.at(idx);
pane->visibilityChanged(true);
bool canNavigate = pane->canNavigate();
m_prevAction->setEnabled(canNavigate && pane->canPrevious());
m_nextAction->setEnabled(canNavigate && pane->canNext());
m_buttons.at(idx)->setChecked(OutputPanePlaceHolder::isCurrentVisible());
m_titleLabel->setText(pane->displayName());
2010-09-16 12:26:28 +02:00
}
lastIndex = idx;
}
2010-09-16 12:26:28 +02:00
void OutputPaneManager::popupMenu()
{
QMenu menu;
int idx = 0;
foreach (IOutputPane *pane, m_panes) {
QAction *act = menu.addAction(pane->displayName());
act->setCheckable(true);
act->setChecked(m_buttonVisibility.value(m_ids.at(idx)));
act->setData(idx);
++idx;
}
QAction *result = menu.exec(QCursor::pos());
if (!result)
return;
idx = result->data().toInt();
Id id = m_ids.at(idx);
QTC_ASSERT(idx >= 0 && idx < m_buttons.size(), return);
QToolButton *button = m_buttons.at(idx);
if (m_buttonVisibility.value(id)) {
m_panes.value(idx)->visibilityChanged(false);
button->setChecked(false);
button->hide();
m_buttonVisibility.insert(id, false);
} else {
button->show();
m_buttonVisibility.insert(id, true);
showPage(idx, IOutputPane::ModeSwitch);
}
}
2010-09-16 12:26:28 +02:00
void OutputPaneManager::saveSettings() const
{
QSettings *settings = ICore::settings();
settings->beginWriteArray(QLatin1String(outputPaneSettingsKeyC),
m_ids.size());
for (int i = 0; i < m_ids.size(); ++i) {
settings->setArrayIndex(i);
settings->setValue(QLatin1String(outputPaneIdKeyC), m_ids.at(i).toSetting());
settings->setValue(QLatin1String(outputPaneVisibleKeyC),
m_buttonVisibility.value(m_ids.at(i)));
}
settings->endArray();
int heightSetting = m_outputPaneHeightSetting;
// update if possible
if (OutputPanePlaceHolder *curr = OutputPanePlaceHolder::getCurrent())
heightSetting = curr->nonMaximizedSize();
settings->setValue(QLatin1String("OutputPanePlaceHolder/Height"), heightSetting);
2010-09-16 12:26:28 +02:00
}
void OutputPaneManager::clearPage()
{
int idx = currentIndex();
if (idx >= 0)
m_panes.at(idx)->clearContents();
}
int OutputPaneManager::currentIndex() const
{
return m_outputWidgetPane->currentIndex();
2010-09-16 12:26:28 +02:00
}
///////////////////////////////////////////////////////////////////////
//
// OutputPaneToolButton
//
///////////////////////////////////////////////////////////////////////
2010-09-16 12:26:28 +02:00
OutputPaneToggleButton::OutputPaneToggleButton(int number, const QString &text,
QAction *action, QWidget *parent)
: QToolButton(parent)
2010-09-16 12:26:28 +02:00
, m_number(QString::number(number))
, m_text(text)
, m_action(action)
, m_flashTimer(new QTimeLine(1000, this))
2010-09-16 12:26:28 +02:00
{
setFocusPolicy(Qt::NoFocus);
setCheckable(true);
QFont fnt = QApplication::font();
setFont(fnt);
2010-09-16 12:26:28 +02:00
if (m_action)
connect(m_action, &QAction::changed, this, &OutputPaneToggleButton::updateToolTip);
m_flashTimer->setDirection(QTimeLine::Forward);
m_flashTimer->setCurveShape(QTimeLine::SineCurve);
m_flashTimer->setFrameRange(0, 92);
auto updateSlot = static_cast<void (QWidget::*)()>(&QWidget::update);
connect(m_flashTimer, &QTimeLine::valueChanged, this, updateSlot);
connect(m_flashTimer, &QTimeLine::finished, this, updateSlot);
updateToolTip();
2010-09-16 12:26:28 +02:00
}
void OutputPaneToggleButton::updateToolTip()
{
QTC_ASSERT(m_action, return);
2010-09-16 12:26:28 +02:00
setToolTip(m_action->toolTip());
}
QSize OutputPaneToggleButton::sizeHint() const
{
ensurePolished();
QSize s = fontMetrics().size(Qt::TextSingleLine, m_text);
// Expand to account for border image
s.rwidth() += numberAreaWidth() + 1 + buttonBorderWidth + buttonBorderWidth;
2010-09-16 12:26:28 +02:00
if (!m_badgeNumberLabel.text().isNull())
s.rwidth() += m_badgeNumberLabel.sizeHint().width() + 1;
2010-09-16 12:26:28 +02:00
return s.expandedTo(QApplication::globalStrut());
}
void OutputPaneToggleButton::paintEvent(QPaintEvent*)
2010-09-16 12:26:28 +02:00
{
static const QImage panelButton(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/panel_button.png")));
static const QImage panelButtonHover(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/panel_button_hover.png")));
static const QImage panelButtonPressed(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/panel_button_pressed.png")));
static const QImage panelButtonChecked(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/panel_button_checked.png")));
static const QImage panelButtonCheckedHover(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/panel_button_checked_hover.png")));
2010-09-16 12:26:28 +02:00
const QFontMetrics fm = fontMetrics();
const int baseLine = (height() - fm.height() + 1) / 2 + fm.ascent();
const int numberWidth = fm.width(m_number);
QPainter p(this);
QStyleOption styleOption;
styleOption.initFrom(this);
const bool hovered = !HostOsInfo::isMacHost() && (styleOption.state & QStyle::State_MouseOver);
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
const QImage *image = 0;
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
if (isDown())
image = &panelButtonPressed;
else if (isChecked())
image = hovered ? &panelButtonCheckedHover : &panelButtonChecked;
else
image = hovered ? &panelButtonHover : &panelButton;
if (image)
StyleHelper::drawCornerImage(*image, &p, rect(), numberAreaWidth(), buttonBorderWidth, buttonBorderWidth, buttonBorderWidth);
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
} else {
Theme::Color c = Theme::BackgroundColorDark;
if (hovered)
c = Theme::BackgroundColorHover;
else if (isDown() || isChecked())
c = Theme::BackgroundColorSelected;
if (c != Theme::BackgroundColorDark)
p.fillRect(rect(), creatorTheme()->color(c));
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
}
if (m_flashTimer->state() == QTimeLine::Running)
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
{
QColor c = creatorTheme()->color(Theme::OutputPaneButtonFlashColor);
c.setAlpha (m_flashTimer->currentFrame());
QRect r = (creatorTheme()->widgetStyle() == Theme::StyleFlat)
? rect() : rect().adjusted(numberAreaWidth(), 1, -1, -1);
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
p.fillRect(r, c);
}
2010-09-16 12:26:28 +02:00
p.setFont(font());
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
p.setPen(creatorTheme()->color(Theme::OutputPaneToggleButtonTextColorChecked));
p.drawText((numberAreaWidth() - numberWidth) / 2, baseLine, m_number);
2010-09-16 12:26:28 +02:00
if (!isChecked())
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
p.setPen(creatorTheme()->color(Theme::OutputPaneToggleButtonTextColorUnchecked));
int leftPart = numberAreaWidth() + buttonBorderWidth;
int labelWidth = 0;
if (!m_badgeNumberLabel.text().isEmpty()) {
const QSize labelSize = m_badgeNumberLabel.sizeHint();
labelWidth = labelSize.width() + 3;
m_badgeNumberLabel.paint(&p, width() - labelWidth, (height() - labelSize.height()) / 2, isChecked());
}
p.drawText(leftPart, baseLine, fm.elidedText(m_text, Qt::ElideRight, width() - leftPart - 1 - labelWidth));
2010-09-16 12:26:28 +02:00
}
void OutputPaneToggleButton::checkStateSet()
{
//Stop flashing when button is checked
QToolButton::checkStateSet();
m_flashTimer->stop();
}
void OutputPaneToggleButton::flash(int count)
{
setVisible(true);
//Start flashing if button is not checked
if (!isChecked()) {
m_flashTimer->setLoopCount(count);
if (m_flashTimer->state() != QTimeLine::Running)
m_flashTimer->start();
update();
}
}
void OutputPaneToggleButton::setIconBadgeNumber(int number)
{
QString text = (number ? QString::number(number) : QString());
m_badgeNumberLabel.setText(text);
updateGeometry();
}
///////////////////////////////////////////////////////////////////////
//
// OutputPaneManageButton
//
///////////////////////////////////////////////////////////////////////
OutputPaneManageButton::OutputPaneManageButton()
{
setFocusPolicy(Qt::NoFocus);
setCheckable(true);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
}
QSize OutputPaneManageButton::sizeHint() const
{
ensurePolished();
return QSize(numberAreaWidth(), QApplication::globalStrut().height());
}
void OutputPaneManageButton::paintEvent(QPaintEvent*)
{
QPainter p(this);
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
static const QImage button(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/panel_manage_button.png")));
StyleHelper::drawCornerImage(button, &p, rect(), buttonBorderWidth, buttonBorderWidth, buttonBorderWidth, buttonBorderWidth);
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
}
QStyle *s = style();
QStyleOption arrowOpt;
arrowOpt.initFrom(this);
arrowOpt.rect = QRect(6, rect().center().y() - 3, 8, 8);
arrowOpt.rect.translate(0, -3);
s->drawPrimitive(QStyle::PE_IndicatorArrowUp, &arrowOpt, &p, this);
arrowOpt.rect.translate(0, 6);
s->drawPrimitive(QStyle::PE_IndicatorArrowDown, &arrowOpt, &p, this);
}
BadgeLabel::BadgeLabel()
{
m_font = QApplication::font();
m_font.setBold(true);
m_font.setPixelSize(11);
}
void BadgeLabel::paint(QPainter *p, int x, int y, bool isChecked)
{
const QRectF rect(QRect(QPoint(x, y), m_size));
p->save();
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
p->setBrush(creatorTheme()->color(isChecked? Theme::BadgeLabelBackgroundColorChecked
: Theme::BadgeLabelBackgroundColorUnchecked));
p->setPen(Qt::NoPen);
p->setRenderHint(QPainter::Antialiasing, true);
p->drawRoundedRect(rect, m_padding, m_padding, Qt::AbsoluteSize);
p->setFont(m_font);
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
p->setPen(creatorTheme()->color(isChecked ? Theme::BadgeLabelTextColorChecked
: Theme::BadgeLabelTextColorUnchecked));
p->drawText(rect, Qt::AlignCenter, m_text);
p->restore();
}
void BadgeLabel::setText(const QString &text)
{
m_text = text;
calculateSize();
}
QString BadgeLabel::text() const
{
return m_text;
}
2010-09-16 12:26:28 +02:00
QSize BadgeLabel::sizeHint() const
{
return m_size;
}
2010-09-16 12:26:28 +02:00
void BadgeLabel::calculateSize()
{
const QFontMetrics fm(m_font);
m_size = fm.size(Qt::TextSingleLine, m_text);
m_size.setWidth(m_size.width() + m_padding * 1.5);
m_size.setHeight(2 * m_padding + 1); // Needs to be uneven for pixel perfect vertical centering in the button
}
} // namespace Internal
} // namespace Core