remove all widget files

This commit is contained in:
Marco Martin 2012-09-25 18:50:20 +02:00
parent 885be389ff
commit 6c42c663bc
74 changed files with 0 additions and 20328 deletions

View File

@ -212,38 +212,8 @@ set(plasma_LIB_SRCS
#
# private/declarative/declarativenetworkaccessmanagerfactory.cpp
# private/declarative/dataenginebindings.cpp
# graphicsview/private/animablegraphicswebview.cpp
# graphicsview/private/focusindicator.cpp
# graphicsview/private/nativetabbar.cpp
# graphicsview/private/style.cpp
# graphicsview/private/kineticscroll.cpp
#
# widgets/label.cpp
# widgets/scrollbar.cpp
# widgets/svgwidget.cpp
# widgets/scrollwidget.cpp
# widgets/textedit.cpp
# widgets/textbrowser.cpp
# widgets/busywidget.cpp
# widgets/checkbox.cpp
# widgets/combobox.cpp
# widgets/declarativewidget.cpp
# widgets/flashinglabel.cpp
# widgets/frame.cpp
# widgets/groupbox.cpp
# widgets/itembackground.cpp
# widgets/lineedit.cpp
# widgets/meter.cpp
# widgets/pushbutton.cpp
# widgets/radiobutton.cpp
# widgets/signalplotter.cpp
# widgets/slider.cpp
# widgets/spinbox.cpp
# widgets/toolbutton.cpp
# widgets/separator.cpp
# widgets/tabbar.cpp
# widgets/treeview.cpp
# widgets/webview.cpp
# )
kconfig_add_kcfg_files(plasma_LIB_SRCS data/kconfigxt/libplasma-theme-global.kcfgc)
@ -342,35 +312,6 @@ install(FILES
${plasma_LIB_INCLUDES}
DESTINATION ${INCLUDE_INSTALL_DIR}/plasma COMPONENT Devel)
install(FILES
widgets/checkbox.h
widgets/combobox.h
widgets/declarativewidget.h
widgets/flashinglabel.h
widgets/frame.h
widgets/groupbox.h
widgets/iconwidget.h
widgets/itembackground.h
widgets/label.h
widgets/lineedit.h
widgets/meter.h
widgets/pushbutton.h
widgets/toolbutton.h
widgets/radiobutton.h
widgets/scrollbar.h
widgets/signalplotter.h
widgets/slider.h
widgets/spinbox.h
widgets/busywidget.h
widgets/separator.h
widgets/svgwidget.h
widgets/scrollwidget.h
widgets/tabbar.h
widgets/textbrowser.h
widgets/treeview.h
widgets/textedit.h
widgets/webview.h
DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/widgets COMPONENT Devel)
install(FILES
scripting/appletscript.h
@ -380,13 +321,6 @@ install(FILES
scripting/scriptengine.h
DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/scripting COMPONENT Devel)
if(PHONON_FOUND)
install (FILES
widgets/videowidget.h
DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/widgets COMPONENT Devel)
endif(PHONON_FOUND)
install(FILES
data/servicetypes/plasma-applet.desktop
data/servicetypes/plasma-applet-popupapplet.desktop

View File

@ -1,193 +0,0 @@
/*
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
* Copyright 2010 Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "animablegraphicswebview_p.h"
#include <QApplication>
#include <QGestureEvent>
#include <QPinchGesture>
#include <QtWebKit/QWebFrame>
#include <qwebpage.h>
#include <kglobalsettings.h>
using namespace Plasma;
AnimableGraphicsWebView::AnimableGraphicsWebView(QGraphicsItem * parent)
: GraphicsWebViewBase(parent)
{
setAcceptTouchEvents(true);
m_dragToScroll = false;
}
void AnimableGraphicsWebView::setDragToScroll(bool enable)
{
m_dragToScroll = enable;
}
bool AnimableGraphicsWebView::dragToScroll() const
{
return m_dragToScroll;
}
QSizeF AnimableGraphicsWebView::contentsSize() const
{
if (!page()) {
return QSizeF();
} else {
return page()->mainFrame()->contentsSize();
}
}
void AnimableGraphicsWebView::setScrollPosition(const QPointF &position)
{
if (!page()) {
return;
} else {
page()->mainFrame()->setScrollPosition(position.toPoint());
}
}
QPointF AnimableGraphicsWebView::scrollPosition() const
{
if (!page() || !page()->mainFrame()) {
return QPointF();
} else {
return page()->mainFrame()->scrollPosition();
}
}
qreal AnimableGraphicsWebView::zoom() const
{
return GraphicsWebViewBase::zoomFactor();
}
void AnimableGraphicsWebView::setZoom(const qreal zoom)
{
GraphicsWebViewBase::setZoomFactor(zoom);
}
QRectF AnimableGraphicsWebView::viewportGeometry() const
{
QRectF result;
if (!page()) {
return result;
} else {
return page()->mainFrame()->geometry();
}
}
void AnimableGraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (!page()) {
GraphicsWebViewBase::mouseMoveEvent(event);
return;
}
if (m_dragToScroll) {
return;
}
QMouseEvent me(QEvent::MouseMove, event->pos().toPoint(), event->button(),
event->buttons(), event->modifiers());
page()->event(&me);
if (me.isAccepted()) {
event->accept();
}
}
void AnimableGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (!page()) {
GraphicsWebViewBase::mousePressEvent(event);
return;
}
m_lastScrollPosition = scrollPosition();
setFocus();
QMouseEvent me(QEvent::MouseButtonPress, event->pos().toPoint(),
event->button(), event->buttons(), event->modifiers());
page()->event(&me);
if (me.isAccepted() && !m_dragToScroll) {
event->accept();
}
}
void AnimableGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (!page()) {
GraphicsWebViewBase::mouseReleaseEvent(event);
return;
}
QMouseEvent me(QEvent::MouseButtonRelease, event->pos().toPoint(),
event->button(),event->buttons(), event->modifiers());
if (!m_dragToScroll || (scrollPosition() - m_lastScrollPosition).manhattanLength() < QApplication::startDragDistance()) {
page()->event(&me);
}
if (me.isAccepted() && !m_dragToScroll) {
event->accept();
}
}
void AnimableGraphicsWebView::wheelEvent(QGraphicsSceneWheelEvent *event)
{
if (!page()) {
GraphicsWebViewBase::wheelEvent(event);
return;
}
QWheelEvent we(event->pos().toPoint(), event->delta(), event->buttons(),
event->modifiers(), event->orientation());
page()->event(&we);
event->setAccepted(!m_dragToScroll);
}
qreal AnimableGraphicsWebView::scrollPositionX() const
{
return page()->mainFrame()->scrollPosition().x();
}
void AnimableGraphicsWebView::setScrollPositionX(qreal position)
{
QPointF pt(position, scrollPositionY());
setScrollPosition(pt);
}
qreal AnimableGraphicsWebView::scrollPositionY() const
{
return page()->mainFrame()->scrollPosition().y();
}
void AnimableGraphicsWebView::setScrollPositionY(qreal position)
{
QPointF pt(scrollPositionX(), position);
setScrollPosition(pt);
}
#include "moc_animablegraphicswebview_p.cpp"

View File

@ -1,83 +0,0 @@
/*
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
* Copyright 2010 Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef ANIMABLEWEBVIEW_P_H
#define ANIMABLEWEBVIEW_P_H
#include <QGraphicsSceneContextMenuEvent>
#include <QGraphicsSceneDragDropEvent>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneWheelEvent>
#include <QGraphicsView>
#include <config-plasma.h>
#if !PLASMA_NO_KDEWEBKIT
#include <kgraphicswebview.h>
#define GraphicsWebViewBase KGraphicsWebView
#else
#include <qgraphicswebview.h>
#define GraphicsWebViewBase QGraphicsWebView
#endif
namespace Plasma
{
class AnimableGraphicsWebView : public GraphicsWebViewBase
{
Q_OBJECT
Q_PROPERTY(qreal zoomFactor READ zoom WRITE setZoom)
Q_PROPERTY(QPointF scrollPosition READ scrollPosition WRITE setScrollPosition)
Q_PROPERTY(qreal scrollPositionX READ scrollPositionX WRITE setScrollPositionX)
Q_PROPERTY(qreal scrollPositionY READ scrollPositionY WRITE setScrollPositionY)
Q_PROPERTY(QSizeF contentsSize READ contentsSize)
Q_PROPERTY(QRectF viewportGeometry READ viewportGeometry)
public:
AnimableGraphicsWebView(QGraphicsItem * parent = 0);
QPointF scrollPosition() const;
void setScrollPosition(const QPointF &position);
qreal scrollPositionX() const;
void setScrollPositionX(qreal position);
qreal scrollPositionY() const;
void setScrollPositionY(qreal position);
QSizeF contentsSize() const;
QRectF viewportGeometry() const;
void setDragToScroll(bool enable);
bool dragToScroll() const;
qreal zoom() const;
void setZoom(const qreal zoom);
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void wheelEvent(QGraphicsSceneWheelEvent *event);
private:
bool m_dragToScroll;
QPointF m_lastScrollPosition;
};
}
#endif

View File

@ -1,53 +0,0 @@
/*
* Copyright 2007-2011 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_CORONA_P_H
#define PLASMA_CORONA_P_H
#include <QTimer>
#include <kactioncollection.h>
class KShortcutsDialog;
namespace Plasma
{
class Containment;
class Corona;
class CoronaPrivate
{
public:
CoronaPrivate(Corona *corona);
~CoronaPrivate();
void init();
void offscreenWidgetDestroyed(QObject *);
static bool s_positioningContainments;
Corona *q;
QHash<uint, QGraphicsWidget*> offscreenWidgets;
CoronaBase *coronaBase;
};
}
#endif

View File

@ -1,322 +0,0 @@
/*
* Copyright 2009 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "focusindicator_p.h"
#include <QGraphicsSceneResizeEvent>
#include <QPainter>
#include <QStringBuilder>
#include <QStyleOptionGraphicsItem>
#include <plasma/theme.h>
#include <plasma/framesvg.h>
#include <plasma/animator.h>
namespace Plasma
{
FocusIndicator::FocusIndicator(QGraphicsWidget *parent, const QString &widget)
: QGraphicsWidget(parent),
m_parent(parent),
m_background(new Plasma::FrameSvg(this)),
m_isUnderMouse(false)
{
m_background->setImagePath(widget);
init(parent);
}
FocusIndicator::FocusIndicator(QGraphicsWidget *parent, FrameSvg *svg)
: QGraphicsWidget(parent),
m_parent(parent),
m_background(svg),
m_isUnderMouse(false)
{
init(parent);
}
void FocusIndicator::init(QGraphicsWidget *parent)
{
setVisible(!Theme::defaultTheme()->useNativeWidgetStyle());
setFlag(QGraphicsItem::ItemStacksBehindParent);
setAcceptsHoverEvents(true);
m_background->setCacheAllRenderedFrames(true);
m_fade = Animator::create(Animator::FadeAnimation, this);
m_fade->setTargetWidget(this);
m_fade->setProperty("startOpacity", 0.0);
m_fade->setProperty("targetOpacity", 1.0);
m_hoverAnimation = Animator::create(Animator::PixmapTransitionAnimation);
m_hoverAnimation->setProperty("duration", 250);
m_hoverAnimation->setTargetWidget(this);
m_testPrefix = "hover";
if (m_background->hasElementPrefix("shadow") ||
m_background->hasElement("shadow")) {
m_prefix = "shadow";
}
parent->installEventFilter(this);
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncGeometry()));
}
FocusIndicator::~FocusIndicator()
{
m_parent->removeEventFilter(this);
delete m_fade;
}
void FocusIndicator::setCustomGeometry(const QRectF &geometry)
{
if (m_customGeometry == geometry) {
return;
}
m_customGeometry = geometry;
syncGeometry();
}
void FocusIndicator::setCustomPrefix(const QString &prefix)
{
QString was = m_prefix;
if (!m_prefix.isEmpty() && !m_customPrefix.isEmpty()) {
m_prefix.remove(m_customPrefix);
}
m_customPrefix = prefix;
if (!m_prefix.isEmpty()) {
m_prefix.prepend(m_customPrefix);
}
m_testPrefix = m_customPrefix % "hover";
if (m_prefix.isEmpty()) {
m_prefix = m_customPrefix % "shadow";
}
if (m_prefix == was) {
return;
}
syncGeometry();
resizeEvent(0);
}
bool FocusIndicator::eventFilter(QObject *watched, QEvent *event)
{
if (Theme::defaultTheme()->useNativeWidgetStyle() ||
static_cast<QGraphicsWidget *>(watched) != m_parent || !m_parent ) {
return false;
}
if (event->type() == QEvent::GraphicsSceneHoverEnter) {
m_isUnderMouse = true;
} else if (event->type() == QEvent::GraphicsSceneHoverLeave) {
m_isUnderMouse = false;
}
switch (event->type()) {
case QEvent::GraphicsSceneHoverEnter:
if (!m_parent->hasFocus()) {
m_prefix = m_customPrefix % "hover";
syncGeometry();
m_hoverAnimation->stop();
if (m_background->hasElementPrefix(m_testPrefix)) {
m_background->setElementPrefix(m_customPrefix % "shadow");
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
m_background->setElementPrefix(m_customPrefix % "hover");
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
} else if (m_background->hasElement(m_testPrefix)) {
m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_customPrefix % "shadow"));
m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_customPrefix % "hover"));
}
m_hoverAnimation->start();
}
break;
case QEvent::GraphicsSceneHoverLeave:
if (!m_parent->hasFocus()) {
m_prefix = m_customPrefix % "shadow";
syncGeometry();
m_hoverAnimation->stop();
if (m_background->hasElementPrefix(m_testPrefix)) {
m_background->setElementPrefix(m_customPrefix % "hover");
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
m_background->setElementPrefix(m_customPrefix % "shadow");
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
} else if (m_background->hasElement(m_testPrefix)) {
m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_customPrefix % "hover"));
m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_customPrefix % "shadow"));
}
m_hoverAnimation->start();
}
break;
case QEvent::GraphicsSceneResize:
syncGeometry();
break;
case QEvent::FocusIn:
m_prefix = m_customPrefix % "focus";
syncGeometry();
m_hoverAnimation->stop();
if (m_background->hasElementPrefix(m_customPrefix % "focus")) {
//m_background->setElementPrefix(m_customPrefix % "shadow");
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
m_background->setElementPrefix(m_customPrefix % "focus");
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
} else if (m_background->hasElement(m_customPrefix % "focus")) {
//m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_customPrefix % "shadow"));
m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_customPrefix % "focus"));
}
m_hoverAnimation->start();
break;
case QEvent::FocusOut:
if (!m_isUnderMouse) {
m_prefix = m_customPrefix % "shadow";
syncGeometry();
m_hoverAnimation->stop();
if (m_background->hasElementPrefix(m_customPrefix % "focus")) {
m_background->setElementPrefix("focus");
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
m_background->setElementPrefix("shadow");
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
} else if (m_background->hasElement(m_customPrefix % "focus")) {
m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_customPrefix % "focus"));
m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_customPrefix % "shadow"));
}
m_hoverAnimation->start();
}
break;
default:
break;
};
return false;
}
void FocusIndicator::resizeEvent(QGraphicsSceneResizeEvent *)
{
if (m_background->hasElementPrefix(m_customPrefix % "shadow")) {
m_background->setElementPrefix(m_customPrefix % "shadow");
m_background->resizeFrame(size());
}
if (m_background->hasElementPrefix(m_customPrefix % "hover")) {
m_background->setElementPrefix(m_customPrefix % "hover");
m_background->resizeFrame(size());
}
if (m_background->hasElementPrefix(m_customPrefix % "focus")) {
m_background->setElementPrefix(m_customPrefix % "focus");
m_background->resizeFrame(size());
}
if (m_hoverAnimation->state() == QAbstractAnimation::Running) {
m_hoverAnimation->stop();
}
if (m_background->hasElementPrefix(m_testPrefix)) {
m_background->setElementPrefix(m_prefix);
m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap());
m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap());
} else if (m_background->hasElement(m_testPrefix)) {
m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_prefix));
m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_prefix));
}
}
void FocusIndicator::animateVisibility(const bool visible)
{
m_fade->setProperty("startOpacity", opacity());
if (visible) {
m_fade->setProperty("targetOpacity", 1.0);
} else {
m_fade->setProperty("targetOpacity", 0);
}
m_fade->start();
}
void FocusIndicator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
painter->drawPixmap(
option->rect,
m_hoverAnimation->property("currentPixmap").value<QPixmap>());
}
void FocusIndicator::syncGeometry()
{
if (Theme::defaultTheme()->useNativeWidgetStyle()) {
hide();
return;
} else if (!isVisible()) {
show();
}
QRectF geom;
if (!m_customGeometry.isEmpty()) {
geom = m_customGeometry;
} else {
geom = m_parent->boundingRect();
}
if (m_background->hasElementPrefix(m_testPrefix)) {
//always take borders from hover to make it stable
m_background->setElementPrefix(m_testPrefix);
qreal left, top, right, bottom;
m_background->getMargins(left, top, right, bottom);
m_background->setElementPrefix(m_prefix);
setGeometry(QRectF(geom.topLeft() + QPointF(-left, -top), geom.size() + QSize(left+right, top+bottom)));
} else if (m_background->hasElement(m_testPrefix)) {
QRectF elementRect = m_background->elementRect(m_testPrefix);
elementRect.moveCenter(geom.center());
setGeometry(elementRect);
}
}
void FocusIndicator::setFrameSvg(FrameSvg *frameSvg)
{
if (m_background != frameSvg) {
m_background = frameSvg;
}
}
FrameSvg *FocusIndicator::frameSvg() const
{
return m_background;
}
}
#include "moc_focusindicator_p.cpp"

View File

@ -1,69 +0,0 @@
/*
* Copyright 2009 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_FOCUSINDICATOR_P
#define PLASMA_FOCUSINDICATOR_P
#include <QGraphicsWidget>
#include <plasma/animations/animation.h>
namespace Plasma
{
class FrameSvg;
class FadeAnimation;
class FocusIndicator : public QGraphicsWidget
{
Q_OBJECT
public:
FocusIndicator(QGraphicsWidget *parent, const QString &widget);
FocusIndicator(QGraphicsWidget *parent, FrameSvg *svg);
~FocusIndicator();
void setCustomGeometry(const QRectF &geometry);
void setCustomPrefix(const QString &prefix);
void animateVisibility(const bool visible);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void setFrameSvg(FrameSvg *svg);
FrameSvg *frameSvg() const;
protected:
bool eventFilter(QObject *watched, QEvent *event);
void resizeEvent(QGraphicsSceneResizeEvent *event);
private Q_SLOTS:
void syncGeometry();
private:
void init(QGraphicsWidget *parent);
QGraphicsWidget *m_parent;
Plasma::FrameSvg *m_background;
Animation *m_fade;
Animation *m_hoverAnimation;
QRectF m_customGeometry;
QString m_prefix;
QString m_customPrefix;
QString m_testPrefix;
bool m_isUnderMouse;
};
}
#endif

View File

@ -1,549 +0,0 @@
/*
* Copyright 2011 by Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "graphicsviewappletprivate_p.h"
#include <QGraphicsLinearLayout>
#include <QGraphicsGridLayout>
#include "kwindowsystem.h"
#include "corona.h"
#include "dialog.h"
#include "paintutils.h"
#include "popupapplet.h"
#include "theme.h"
#include "tooltipmanager.h"
#include "widgets/busywidget.h"
#include "widgets/iconwidget.h"
#include "widgets/label.h"
#include "widgets/pushbutton.h"
namespace Plasma
{
GraphicsViewAppletPrivate::GraphicsViewAppletPrivate(KService::Ptr service, const KPluginInfo *info, int uniqueID, Applet *applet)
: AppletPrivate(service, info, uniqueID, applet),
messageOverlay(0),
messageOverlayProxy(0),
busyWidget(0)
{
q->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
q->setAcceptsHoverEvents(true);
q->setFlag(QGraphicsItem::ItemIsFocusable, true);
q->setFocusPolicy(Qt::ClickFocus);
// FIXME: adding here because nothing seems to be doing it in QGraphicsView,
// but it doesn't actually work anyways =/
q->setLayoutDirection(qApp->layoutDirection());
}
void GraphicsViewAppletPrivate::showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons)
{
if (message.isEmpty()) {
destroyMessageOverlay();
return;
}
Corona *corona = qobject_cast<Corona *>(q->scene());
QGraphicsWidget *mainWidget = new QGraphicsWidget;
QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(mainWidget);
mainLayout->setOrientation(Qt::Vertical);
mainLayout->addStretch();
QGraphicsLinearLayout *messageLayout = new QGraphicsLinearLayout();
messageLayout->setOrientation(Qt::Horizontal);
QGraphicsLinearLayout *buttonLayout = new QGraphicsLinearLayout();
buttonLayout->setOrientation(Qt::Horizontal);
mainLayout->addItem(messageLayout);
mainLayout->addItem(buttonLayout);
mainLayout->addStretch();
IconWidget *messageIcon = new IconWidget(mainWidget);
Label *messageText = new Label(mainWidget);
messageText->nativeWidget()->setWordWrap(true);
messageLayout->addStretch();
messageLayout->addItem(messageIcon);
messageLayout->addItem(messageText);
messageLayout->addStretch();
messageIcon->setIcon(icon);
messageText->setText(message);
buttonLayout->addStretch();
if (buttons & ButtonOk) {
messageOkButton = new PushButton(mainWidget);
messageOkButton.data()->setText(i18n("&OK"));
messageOkButton.data()->setIcon(KDE::icon("dialog-ok"));
buttonLayout->addItem(messageOkButton.data());
QObject::connect(messageOkButton.data(), SIGNAL(clicked()), q, SLOT(destroyMessageOverlay()));
}
if (buttons & ButtonYes) {
messageYesButton = new PushButton(mainWidget);
messageYesButton.data()->setText(i18n("&Yes"));
buttonLayout->addItem(messageYesButton.data());
QObject::connect(messageYesButton.data(), SIGNAL(clicked()), q, SLOT(destroyMessageOverlay()));
}
if (buttons & ButtonNo) {
messageNoButton = new PushButton(mainWidget);
messageNoButton.data()->setText(i18n("&No"));
buttonLayout->addItem(messageNoButton.data());
QObject::connect(messageNoButton.data(), SIGNAL(clicked()), q, SLOT(destroyMessageOverlay()));
}
if (buttons & ButtonCancel) {
messageCancelButton = new PushButton(mainWidget);
messageCancelButton.data()->setText(i18n("&Cancel"));
messageCancelButton.data()->setIcon(KDE::icon("dialog-cancel"));
buttonLayout->addItem(messageCancelButton.data());
QObject::connect(messageCancelButton.data(), SIGNAL(clicked()), q, SLOT(destroyMessageOverlay()));
}
messageCloseAction = new QAction(messageOverlay);
messageCloseAction.data()->setShortcut(Qt::Key_Escape);
mainWidget->addAction(messageCloseAction.data());
QObject::connect(messageCloseAction.data(), SIGNAL(triggered()), q, SLOT(destroyMessageOverlay()));
buttonLayout->addStretch();
mainWidget->adjustSize();
QSizeF hint = mainWidget->preferredSize();
if (hint.height() > q->size().height() || hint.width() > q->size().width()) {
// either a collapsed popup in h/v form factor or just too small,
// so show it in a dialog associated with ourselves
if (corona) {
corona->addOffscreenWidget(mainWidget);
}
if (messageDialog) {
delete messageDialog.data()->graphicsWidget();
} else {
messageDialog = new Plasma::Dialog;
}
ToolTipManager::self()->hide(q);
KWindowSystem::setOnAllDesktops(messageDialog.data()->winId(), true);
KWindowSystem::setState(messageDialog.data()->winId(), NET::SkipTaskbar | NET::SkipPager);
messageDialog.data()->setGraphicsWidget(mainWidget);
QObject::connect(messageDialog.data(), SIGNAL(destroyed(QObject*)), mainWidget, SLOT(deleteLater()));
// if we are going to show it in a popup, then at least make sure it can be dismissed
if (buttonLayout->count() < 1) {
PushButton *ok = new PushButton(mainWidget);
ok->setText(i18n("OK"));
ok->setIcon(KDE::icon("dialog-ok"));
buttonLayout->addItem(ok);
QObject::connect(ok, SIGNAL(clicked()), q, SLOT(destroyMessageOverlay()));
}
} else {
delete messageDialog.data();
createMessageOverlay();
messageOverlay->opacity = 0.8;
mainWidget->setParentItem(messageOverlay);
QGraphicsLinearLayout *l = new QGraphicsLinearLayout(messageOverlay);
l->addItem(mainWidget);
}
if (messageDialog) {
QPoint pos = q->geometry().topLeft().toPoint();
if (corona) {
pos = corona->popupPosition(q, messageDialog.data()->size());
}
messageDialog.data()->move(pos);
messageDialog.data()->animatedShow(locationToDirection(q->location()));
} else {
messageOverlay->show();
}
}
void GraphicsViewAppletPrivate::updateFailedToLaunch(const QString &reason)
{
if (failed == failed) {
if (failed && !reason.isEmpty()) {
foreach (QGraphicsItem *item, q->QGraphicsItem::children()) {
Label *l = dynamic_cast<Label *>(item);
if (l) {
l->setText(visibleFailureText(reason));
}
}
}
return;
}
//FIXME: q->prepareGeometryChange();
foreach (QGraphicsItem *item, q->childItems()) {
if (!dynamic_cast<AppletHandle *>(item)) {
delete item;
}
}
messageOverlay = 0;
if (messageDialog) {
messageDialog.data()->deleteLater();
messageDialog.clear();
}
q->setLayout(0);
if (failed) {
q->setBackgroundHints(StandardBackground);
QGraphicsLinearLayout *failureLayout = new QGraphicsLinearLayout(q);
failureLayout->setContentsMargins(0, 0, 0, 0);
IconWidget *failureIcon = new IconWidget(q);
failureIcon->setIcon(KDE::icon("dialog-error"));
failureLayout->addItem(failureIcon);
Label *failureWidget = new Plasma::Label(q);
failureWidget->setText(visibleFailureText(reason));
QLabel *label = failureWidget->nativeWidget();
label->setWordWrap(true);
failureLayout->addItem(failureWidget);
Plasma::ToolTipManager::self()->registerWidget(failureIcon);
Plasma::ToolTipContent data(i18n("Unable to load the widget"), reason,
KDE::icon("dialog-error"));
Plasma::ToolTipManager::self()->setContent(failureIcon, data);
q->setLayout(failureLayout);
q->resize(300, 250);
background->resizeFrame(q->geometry().size());
}
q->update();
}
void GraphicsViewAppletPrivate::cleanUpAndDelete()
{
//kDebug() << "???????????????? DESTROYING APPLET" << q->name() << q->scene() << " ???????????????????????????";
QGraphicsWidget *parent = dynamic_cast<QGraphicsWidget *>(q->parentItem());
//it probably won't matter, but right now if there are applethandles, *they* are the parent.
//not the containment.
//is the applet in a containment and does the containment have a layout?
//if yes, we remove the applet in the layout
if (parent && parent->layout()) {
QGraphicsLayout *l = parent->layout();
for (int i = 0; i < l->count(); ++i) {
if (q == l->itemAt(i)) {
l->removeAt(i);
break;
}
}
}
if (configLoader) {
configLoader->setDefaults();
}
resetConfigurationObject();
if (q->scene()) {
if (isContainment) {
// prematurely emit our destruction if we are a Containment,
// giving Corona a chance to remove this Containment from its collection
emit q->QObject::destroyed(q);
}
q->scene()->removeItem(q);
}
q->deleteLater();
}
void GraphicsViewAppletPrivate::showConfigurationRequiredMessage(bool show, const QString &reason)
{
if (!show) {
destroyMessageOverlay();
return;
}
createMessageOverlay(true);
messageOverlay->opacity = 0.4;
QGraphicsGridLayout *configLayout = new QGraphicsGridLayout(messageOverlay);
configLayout->setContentsMargins(0, 0, 0, 0);
// configLayout->addStretch();
configLayout->setColumnStretchFactor(0, 5);
configLayout->setColumnStretchFactor(2, 5);
configLayout->setRowStretchFactor(0, 5);
configLayout->setRowStretchFactor(3, 5);
int row = 1;
if (!reason.isEmpty()) {
Label *explanation = new Label(messageOverlay);
explanation->setText(reason);
configLayout->addItem(explanation, row, 1);
configLayout->setColumnStretchFactor(1, 5);
++row;
configLayout->setAlignment(explanation, Qt::AlignBottom | Qt::AlignCenter);
}
PushButton *configWidget = new PushButton(messageOverlay);
QObject::connect(configWidget, SIGNAL(clicked()), q, SLOT(showConfigurationInterface()));
const FormFactor formFactor = q->formFactor();
if (!qobject_cast<Plasma::PopupApplet *>(q) && (formFactor == Plasma::Horizontal || formFactor == Plasma::Vertical)) {
configWidget->setImage("widgets/configuration-icons", "configure");
configWidget->setMaximumSize(24,24);
configWidget->setMinimumSize(24,24);
} else {
configWidget->setText(i18n("Configure..."));
}
configLayout->addItem(configWidget, row, 1);
//configLayout->setAlignment(configWidget, Qt::AlignTop | Qt::AlignCenter);
//configLayout->addStretch();
messageOverlay->show();
}
void GraphicsViewAppletPrivate::createMessageOverlay(bool usePopup)
{
if (messageOverlay) {
qDeleteAll(messageOverlay->children());
messageOverlay->setLayout(0);
}
PopupApplet *popup = qobject_cast<Plasma::PopupApplet*>(q);
if (!messageOverlay) {
if (usePopup && popup) {
if (popup->widget()) {
messageOverlayProxy = new QGraphicsProxyWidget(q);
messageOverlayProxy->setWidget(popup->widget());
messageOverlay = new AppletOverlayWidget(messageOverlayProxy);
} else if (popup->graphicsWidget()) {
messageOverlay = new AppletOverlayWidget(popup->graphicsWidget());
}
}
if (!messageOverlay) {
messageOverlay = new AppletOverlayWidget(q);
}
}
positionMessageOverlay();
}
void GraphicsViewAppletPrivate::positionMessageOverlay()
{
if (!messageOverlay) {
return;
}
PopupApplet *popup = qobject_cast<Plasma::PopupApplet*>(q);
const bool usePopup = popup && (messageOverlay->parentItem() != q);
QGraphicsItem *topItem = q;
if (usePopup && popup->widget()) {
// popupapplet with widget()
//FIXME:topItem = popup->d->proxy.data();
messageOverlay->setGeometry(popup->widget()->contentsRect());
} else if (usePopup && popup->graphicsWidget()) {
// popupapplet with graphicsWidget()
topItem = popup->graphicsWidget();
QGraphicsWidget *w = dynamic_cast<QGraphicsWidget *>(topItem);
messageOverlay->setGeometry(w ? w->contentsRect() : topItem->boundingRect());
} else {
// normal applet
messageOverlay->setGeometry(q->contentsRect());
}
// raise the overlay above all the other children!
int zValue = 100;
foreach (QGraphicsItem *child, topItem->children()) {
if (child->zValue() > zValue) {
zValue = child->zValue() + 1;
}
}
messageOverlay->setZValue(zValue);
}
void GraphicsViewAppletPrivate::destroyMessageOverlay()
{
if (messageDialog) {
messageDialog.data()->animatedHide(Plasma::locationToInverseDirection(q->location()));
//messageDialog.data()->deleteLater();
messageDialog.clear();
}
if (!messageOverlay) {
return;
}
messageOverlay->destroy();
messageOverlay = 0;
if (messageOverlayProxy) {
messageOverlayProxy->setWidget(0);
delete messageOverlayProxy;
messageOverlayProxy = 0;
}
MessageButton buttonCode = ButtonNo;
//find out if we're disappearing because of a button press
PushButton *button = 0;
//FIXME: PushButton *button = qobject_cast<PushButton *>(q->sender());
if (button) {
if (button == messageOkButton.data()) {
buttonCode = ButtonOk;
}
if (button == messageYesButton.data()) {
buttonCode = ButtonYes;
}
if (button == messageNoButton.data()) {
buttonCode = ButtonNo;
}
if (button == messageCancelButton.data()) {
buttonCode = ButtonCancel;
}
//FIXME: emit q->messageButtonPressed(buttonCode);
} else if (/* FIXME: q->sender() == messageOverlay */ false) {
//FIXME: emit q->messageButtonPressed(ButtonCancel);
}
}
void GraphicsViewAppletPrivate::setBusy(bool busy)
{
if (busy) {
if (!busyWidget && !busyWidgetTimer.isActive()) {
busyWidgetTimer.start(500, this);
}
} else {
busyWidgetTimer.stop();
if (busyWidget) {
busyWidget = 0;
destroyMessageOverlay();
}
}
}
bool GraphicsViewAppletPrivate::isBusy() const
{
return busyWidgetTimer.isActive() || (busyWidget && busyWidget->isVisible());
}
void GraphicsViewAppletPrivate::timerEvent(QTimerEvent *event)
{
if (transient) {
busyWidgetTimer.stop();
return;
}
if (event->timerId() == busyWidgetTimer.timerId()) {
if (!busyWidget) {
createMessageOverlay(false);
messageOverlay->opacity = 0;
QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(messageOverlay);
busyWidget = new Plasma::BusyWidget(messageOverlay);
busyWidget->setAcceptHoverEvents(false);
busyWidget->setAcceptedMouseButtons(Qt::NoButton);
messageOverlay->setAcceptHoverEvents(false);
messageOverlay->setAcceptedMouseButtons(Qt::NoButton);
mainLayout->addStretch();
mainLayout->addItem(busyWidget);
mainLayout->addStretch();
}
}
}
AppletOverlayWidget::AppletOverlayWidget(QGraphicsWidget *parent)
: QGraphicsWidget(parent),
opacity(0.4)
{
resize(parent->size());
}
void AppletOverlayWidget::destroy()
{
/*FIXME: a transitional animation would be nice here .. we used to do this:
Animation *anim = Plasma::Animator::create(Plasma::Animator::DisappearAnimation);
if (anim) {
connect(anim, SIGNAL(finished()), this, SLOT(overlayAnimationComplete()));
anim->setTargetWidget(this);
anim->start();
} else {
overlayAnimationComplete();
}
*/
if (scene()) {
scene()->removeItem(this);
}
deleteLater();
}
void AppletOverlayWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
}
void AppletOverlayWidget::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
if (qFuzzyCompare(1, 1+opacity)) {
return;
}
QColor wash = Plasma::Theme::defaultTheme()->color(Theme::BackgroundColor);
wash.setAlphaF(opacity);
Applet *applet = qobject_cast<Applet *>(parentWidget());
QPainterPath backgroundShape;
if (!applet || applet->backgroundHints() == StandardBackground) {
//FIXME: a resize here is nasty, but perhaps still better than an eventfilter just for that..
if (parentWidget()->contentsRect().size() != size()) {
resize(parentWidget()->contentsRect().size());
}
backgroundShape = PaintUtils::roundedRectangle(contentsRect(), 5);
} else {
backgroundShape = shape();
}
painter->setRenderHints(QPainter::Antialiasing);
painter->fillPath(backgroundShape, wash);
}
} // namespace Plasma
#include "graphicsviewappletprivate_p.h"

View File

@ -1,82 +0,0 @@
/*
* Copyright 2011 by Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_GRAPHICSVIEWAPPLETPRIVATE_H
#define PLASMA_GRAPHICSVIEWAPPLETPRIVATE_H
#include "private/applet_p.h"
namespace Plasma
{
class AppletOverlayWidget : public QGraphicsWidget
{
Q_OBJECT
public:
AppletOverlayWidget(QGraphicsWidget *parent);
void destroy();
qreal opacity;
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
};
class GraphicsViewAppletPrivate : public QObject, public AppletPrivate
{
Q_OBJECT
public:
GraphicsViewAppletPrivate(KService::Ptr service, const KPluginInfo *info, int uniqueID, Applet *applet);
void cleanUpAndDelete();
void showConfigurationRequiredMessage(bool show, const QString &reason);
void showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons);
void positionMessageOverlay();
void setBusy(bool busy);
bool isBusy() const;
void updateFailedToLaunch(const QString &reason);
protected:
void timerEvent(QTimerEvent *event);
private:
void createMessageOverlay(bool usePopup = true);
private Q_SLOTS:
void destroyMessageOverlay();
private:
// overlays and messages
QWeakPointer<Plasma::Dialog> messageDialog;
AppletOverlayWidget *messageOverlay;
QGraphicsProxyWidget *messageOverlayProxy;
Plasma::BusyWidget *busyWidget;
QWeakPointer<Plasma::PushButton> messageOkButton;
QWeakPointer<Plasma::PushButton> messageYesButton;
QWeakPointer<Plasma::PushButton> messageNoButton;
QWeakPointer<Plasma::PushButton> messageCancelButton;
QWeakPointer<QAction> messageCloseAction;
};
} // namespace Plasma
#endif

View File

@ -1,484 +0,0 @@
/*
Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "kineticscroll_p.h"
#include <QtCore/qglobal.h>
#include <QtCore/qmetatype.h>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneWheelEvent>
#include <QTime>
#include <QGraphicsWidget>
#include <QPoint>
#include <QPropertyAnimation>
#include <QCursor>
#include <kdebug.h>
/* TODO:
* - clean up the code(remove duplicated code, constify)
* - port to Plasma::Animator
*/
namespace Plasma
{
class KineticScrollingPrivate
{
public:
enum Direction {
None,
Up,
Down,
Left,
Right
};
enum Gesture {
GestureNone = 0,
GestureUndefined,
GestureScroll,
GestureZoom
};
KineticScrollingPrivate()
: overshoot(20),
hasOvershoot(true),
parent(0),
forwardingEvent(false),
multitouchGesture(GestureNone)
{
}
void count()
{
t = QTime::currentTime();
}
void syncViewportRect()
{
contentsSize = parent->property("contentsSize").toSizeF();
viewportGeometry = parent->property("viewportGeometry").toRectF();
}
bool canScroll(Direction direction, bool hasOvershoot = false) const
{
QPointF scrollPosition = -parent->property("scrollPosition").value<QPointF>();
int offset = (hasOvershoot?overshoot*2:0);
switch (direction) {
case Up:
return (scrollPosition.y() < offset);
case Down:
return (scrollPosition.y() + contentsSize.height() + offset >= viewportGeometry.bottom());
case Left:
return (scrollPosition.x() < offset);
case Right:
return (scrollPosition.x() + contentsSize.width() + offset >= viewportGeometry.right());
default:
return true;
}
}
QPointF kinMovement;
enum BounceStatus {
Running,
Finished
};
BounceStatus bounceStatus;
QPropertyAnimation *scrollAnimation;
int overshoot;
QPointF cposition;
bool hasOvershoot;
QGraphicsWidget *parent;
QRectF viewportGeometry;
QSizeF contentsSize;
QPointF maximum, minimum;
bool forwardingEvent;
Gesture multitouchGesture;
unsigned int timeDelta;
QTime t;
};
KineticScrolling::KineticScrolling(QGraphicsWidget *parent)
: d(new KineticScrollingPrivate)
{
setWidget(parent);
}
KineticScrolling::~KineticScrolling()
{
delete d;
}
void KineticScrolling::duration( )
{
d->timeDelta = d->t.msecsTo(QTime::currentTime());
}
void KineticScrolling::overshoot()
{
QPointF scrollPosition = -d->parent->property("scrollPosition").value<QPointF>();
if (!d->canScroll(KineticScrollingPrivate::Down) &&
!d->canScroll(KineticScrollingPrivate::Up)) {
return;
}
if (d->bounceStatus != KineticScrollingPrivate::Running) {
if ((d->cposition.y() > 0 ) || (d->cposition.y() <= d->minimum.y() + d->overshoot)) {
QPointF finalPosition;
d->scrollAnimation->setEasingCurve( QEasingCurve::OutBounce );
if (d->cposition.y() > 0) {
finalPosition = QPointF(scrollPosition.x(), 0);
} else {
finalPosition = QPointF(d->cposition.x(),
-d->contentsSize.height( ) + d->parent->size().height());
}
resetAnimation(-finalPosition, 900);
d->bounceStatus = KineticScrollingPrivate::Running;
}
} else {
d->bounceStatus = KineticScrollingPrivate::Finished;
d->scrollAnimation->setEasingCurve(QEasingCurve::OutCirc);
}
}
void KineticScrolling::setScrollValue(QPointF value)
{
const QPointF pos = thresholdPosition(value);
QPointF posf(-pos);
d->parent->setProperty("scrollPosition", posf);
if ((pos.y() == d->overshoot) || (pos.y() == d->minimum.y())) {
overshoot();
}
}
QPointF KineticScrolling::thresholdPosition(QPointF value) const
{
d->minimum.setX(-d->contentsSize.width() + d->viewportGeometry.width());
d->minimum.setY(-d->contentsSize.height() + d->viewportGeometry.height()
-d->overshoot);
d->minimum.setY(qMin((qreal)d->overshoot, d->minimum.y()));
d->maximum = value;
if(d->minimum.x() >= 0) {
d->cposition.setX(value.x());
} else {
d->cposition.setX(qBound(d->minimum.x(), d->maximum.x(), qreal(0)));
}
if((-d->contentsSize.height() + d->viewportGeometry.height() - d->overshoot) >= 0) {
d->cposition.setY(value.y());
} else {
d->cposition.setY(qBound(d->minimum.y(), d->maximum.y(), qreal(d->overshoot)));
}
return d->cposition;
}
void KineticScrolling::resetAnimation(QPointF finalPosition, int duration)
{
if (d->scrollAnimation->state() != QAbstractAnimation::Stopped) {
d->scrollAnimation->stop();
}
d->cposition = -finalPosition;
QPointF tmpPosition = d->parent->property("scrollPosition").value<QPointF>();
d->scrollAnimation->setStartValue(tmpPosition);
tmpPosition = finalPosition;
d->scrollAnimation->setEndValue(tmpPosition);
d->scrollAnimation->setDuration(duration);
d->scrollAnimation->start();
}
void KineticScrolling::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event);
if (d->scrollAnimation->state() != QAbstractAnimation::Stopped) {
d->scrollAnimation->stop();
}
d->syncViewportRect();
d->cposition = -d->parent->property("scrollPosition").value<QPointF>();
d->count();
d->kinMovement = QPointF(0,0);
d->scrollAnimation->setEasingCurve(QEasingCurve::OutCirc);
}
void KineticScrolling::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
QPointF movement = event->lastPos().toPoint() - event->pos().toPoint();
const QPointF scrollPosition = -d->parent->property("scrollPosition").value<QPointF>();
if (!movement.isNull()) {
if ((d->contentsSize.width() < d->viewportGeometry.width()) &&
(d->contentsSize.height() < d->viewportGeometry.height())) {
d->kinMovement = QPointF(0, 0);
movement = QPointF(0, 0);
} else if (d->contentsSize.height() < d->viewportGeometry.height()) {
d->kinMovement += QPointF(movement.x(), 0);
movement.setY(0);
} else if (d->contentsSize.width() < d->viewportGeometry.width()) {
d->kinMovement = QPointF(0, movement.y());
movement.setX(0);
} else {
d->kinMovement += movement;
}
setScrollValue(scrollPosition - movement);
}
}
void KineticScrolling::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event);
if (d->scrollAnimation->state() != QAbstractAnimation::Running) {
duration();
if (d->kinMovement != QPointF(0, 0)) {
const QPointF scrollPosition = -d->parent->property("scrollPosition").toPointF();
d->kinMovement = QPointF(d->kinMovement.x()*3, d->kinMovement.y()*3);
const QPointF finalPos = thresholdPosition(scrollPosition - d->kinMovement);
resetAnimation( -finalPos, d->timeDelta*8 );
}
}
}
void KineticScrolling::wheelReleaseEvent(QGraphicsSceneWheelEvent *event)
{
Q_UNUSED(event);
d->syncViewportRect();
d->kinMovement = QPointF(0,0);
if((event->orientation() == Qt::Vertical) &&
(((event->delta() < 0) && d->canScroll(KineticScrollingPrivate::Down)) ||
((event->delta() > 0) && d->canScroll(KineticScrollingPrivate::Up)))) {
d->kinMovement.setY(d->kinMovement.y() - event->delta());
} else if ((event->orientation() == Qt::Vertical) ||
(!d->canScroll(KineticScrollingPrivate::Down) &&
!d->canScroll(KineticScrollingPrivate::Up))) {
if (((event->delta() < 0) &&
d->canScroll(KineticScrollingPrivate::Right)) ||
(event->delta() > 0 && d->canScroll(KineticScrollingPrivate::Left))) {
d->kinMovement.setX(d->kinMovement.x() - event->delta());
} else {
event->ignore( );
}
} else {
event->ignore( );
return;
}
const QPointF scrollPosition = -d->parent->property("scrollPosition").value<QPointF>();
const QPointF pos = scrollPosition - d->kinMovement*2;
const QPointF finalPos = thresholdPosition(pos);
d->scrollAnimation->setEasingCurve(QEasingCurve::OutCirc);
resetAnimation(-finalPos, 900);
}
void KineticScrolling::keyPressEvent(QKeyEvent *event)
{
const int movement = 30;
const int duration = 900;
QPointF scrollPosition = -d->parent->property("scrollPosition").value<QPointF>();
QPointF finalPos;
switch (event->key()) {
case Qt::Key_Left:
scrollPosition.setX(scrollPosition.x() + movement);
finalPos = thresholdPosition(scrollPosition);
resetAnimation(-finalPos, duration);
break;
case Qt::Key_Right:
scrollPosition.setX(scrollPosition.x() - movement);
finalPos = thresholdPosition(scrollPosition);
resetAnimation(-finalPos, duration);
break;
case Qt::Key_Up:
scrollPosition.setY(scrollPosition.y() + movement);
finalPos = thresholdPosition(scrollPosition);
resetAnimation(-finalPos, duration);
break;
case Qt::Key_Down:
scrollPosition.setY(scrollPosition.y() - movement);
finalPos = thresholdPosition(scrollPosition);
resetAnimation(-finalPos, duration);
break;
default:
break;
}
}
void KineticScrolling::setWidget(QGraphicsWidget *parent)
{
if (d->parent) {
d->parent->removeEventFilter(this);
disconnect(d->scrollAnimation, SIGNAL(finished()), this, SLOT(overshoot()));
disconnect(d->scrollAnimation,
SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)), this,
SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));
delete d->scrollAnimation;
}
setParent(parent);
d->parent = parent;
d->scrollAnimation = new QPropertyAnimation(parent, "scrollPosition", parent);
connect(d->scrollAnimation, SIGNAL(finished()), this, SLOT(overshoot()));
connect(d->scrollAnimation,
SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)), this,
SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));
d->scrollAnimation->setEasingCurve(QEasingCurve::OutCirc);
if (parent) {
d->parent->installEventFilter(this);
}
/* TODO: add a new property in plasma::ScrollWidget 'hasOvershoot' */
}
void KineticScrolling::stop()
{
d->scrollAnimation->stop();
}
bool KineticScrolling::eventFilter(QObject *watched, QEvent *event)
{
Q_UNUSED(watched);
Q_UNUSED(event);
if (d->forwardingEvent) {
return false;
}
bool notBlocked = true;
if (d->multitouchGesture == KineticScrollingPrivate::GestureNone &&
d->parent && d->parent->scene()) {
d->forwardingEvent = true;
notBlocked = d->parent->scene()->sendEvent(d->parent, event);
d->forwardingEvent = false;
}
if (event->type() != QEvent::TouchBegin &&
event->type() != QEvent::TouchUpdate &&
event->type() != QEvent::TouchEnd &&
(!notBlocked ||
((event->type() != QEvent::GraphicsSceneMousePress && event->isAccepted()) &&
(event->type() != QEvent::GraphicsSceneWheel && event->isAccepted())))) {
return true;
}
QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(event);
QGraphicsSceneWheelEvent *we = static_cast<QGraphicsSceneWheelEvent *>(event);
switch (event->type()) {
case QEvent::GraphicsSceneMousePress:
mousePressEvent(me);
break;
case QEvent::GraphicsSceneMouseRelease:
mouseReleaseEvent(me);
break;
case QEvent::GraphicsSceneMouseMove:
mouseMoveEvent(me);
break;
case QEvent::TouchBegin:
mousePressEvent(0);
break;
case QEvent::TouchUpdate: {
QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
if (touchPoints.count() == 2) {
const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
const QLineF line0(touchPoint0.lastPos(), touchPoint1.lastPos());
const QLineF line1(touchPoint0.pos(), touchPoint1.pos());
const QLineF startLine(touchPoint0.startPos(), touchPoint1.startPos());
const QPointF point = line1.pointAt(0.5);
const QPointF lastPoint = line0.pointAt(0.5);
if (d->multitouchGesture == KineticScrollingPrivate::GestureNone) {
d->multitouchGesture = KineticScrollingPrivate::GestureUndefined;
}
if (d->multitouchGesture == KineticScrollingPrivate::GestureUndefined) {
const int zoomDistance = qAbs(line1.length() - startLine.length());
const int dragDistance = (startLine.pointAt(0.5) - point).manhattanLength();
if (zoomDistance - dragDistance > 30) {
d->multitouchGesture = KineticScrollingPrivate::GestureZoom;
} else if (dragDistance - zoomDistance > 30) {
d->multitouchGesture = KineticScrollingPrivate::GestureScroll;
}
}
if (d->multitouchGesture == KineticScrollingPrivate::GestureScroll) {
QGraphicsSceneMouseEvent fakeEvent;
fakeEvent.setPos(point);
fakeEvent.setLastPos(lastPoint);
mouseMoveEvent(&fakeEvent);
} else if (d->multitouchGesture == KineticScrollingPrivate::GestureZoom) {
qreal scaleFactor = 1;
if (line0.length() > 0) {
scaleFactor = line1.length() / line0.length();
}
qreal zoom = d->parent->property("zoomFactor").toReal();
d->parent->setProperty("zoomFactor", zoom * scaleFactor);
}
}
break;
}
case QEvent::TouchEnd:
mouseReleaseEvent(0);
d->multitouchGesture = KineticScrollingPrivate::GestureNone;
break;
case QEvent::GraphicsSceneWheel:
wheelReleaseEvent(we);
break;
case QEvent::KeyPress: {
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
keyPressEvent(ke);
break;
}
default:
break;
}
return true;
}
} // namespace Plasma

View File

@ -1,73 +0,0 @@
/*
Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PLASMA_KINETICSCROLLING_H
#define PLASMA_KINETICSCROLLING_H
class QGraphicsSceneMouseEvent;
class QGraphicsWidget;
class QGraphicsSceneWheelEvent;
class QKeyEvent;
#include <QObject>
#include <QPointF>
#include <QtCore/QAbstractAnimation>
namespace Plasma
{
class KineticScrollingPrivate;
class KineticScrolling: public QObject
{
Q_OBJECT
public:
KineticScrolling(QGraphicsWidget *parent);
~KineticScrolling();
void setWidget(QGraphicsWidget *parent);
void stop();
Q_SIGNALS:
void stateChanged(QAbstractAnimation::State newState,
QAbstractAnimation::State oldState);
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void wheelReleaseEvent(QGraphicsSceneWheelEvent *event);
void keyPressEvent(QKeyEvent *event);
private:
KineticScrollingPrivate *d;
void resetAnimation(QPointF finalPosition, int duration);
void setScrollValue(QPointF value);
QPointF thresholdPosition(QPointF value) const;
void duration();
private Q_SLOTS:
void overshoot();
protected:
bool eventFilter(QObject *watched, QEvent *event);
};
}
#endif

View File

@ -1,634 +0,0 @@
/*
Copyright 2007 Robert Knight <robertknight@gmail.com>
Copyright 2008 Marco Martin <notmart@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
// Own
#include "nativetabbar_p.h"
// Qt
#include <QIcon>
#include <QMouseEvent>
#include <QPainter>
#include <QApplication>
#include <QStyleOption>
#include <QToolButton>
#include <QPropertyAnimation>
#include <QWeakPointer>
#include <QGradient>
#include <QLinearGradient>
// KDE
#include <kdebug.h>
#include <kiconeffect.h>
#include <kiconloader.h>
#include "plasma/plasma.h"
#include "plasma/theme.h"
#include "plasma/animator.h"
#include "plasma/framesvg.h"
#include "plasma/paintutils.h"
namespace Plasma
{
static const int buttonHMargin = 4;
static const int buttonVMargin = 3;
static const int iconSpacing = 4;
class NativeTabBarPrivate
{
public:
NativeTabBarPrivate(NativeTabBar *parent)
: q(parent),
shape(NativeTabBar::RoundedNorth),
backgroundSvg(0),
buttonSvg(0),
m_highlightSvg(0)
{
backgroundSvg = new FrameSvg(q);
backgroundSvg->setImagePath("widgets/frame");
backgroundSvg->setElementPrefix("sunken");
buttonSvg = new FrameSvg(q);
buttonSvg->setImagePath("widgets/button");
buttonSvg->setElementPrefix("normal");
syncBorders();
lastIndex[0] = -1;
lastIndex[1] = -1;
}
~NativeTabBarPrivate()
{
delete backgroundSvg;
delete buttonSvg;
}
void syncBorders();
void storeLastIndex();
FrameSvg *highlightSvg()
{
if (!m_highlightSvg) {
m_highlightSvg = new FrameSvg(q);
m_highlightSvg->setImagePath("widgets/button");
m_highlightSvg->setElementPrefix("pressed");
}
return m_highlightSvg;
}
NativeTabBar *q;
QTabBar::Shape shape; //used to keep track of shape() changes
FrameSvg *backgroundSvg;
qreal left, top, right, bottom;
FrameSvg *buttonSvg;
qreal buttonLeft, buttonTop, buttonRight, buttonBottom;
QList<bool> highlightedTabs;
QWeakPointer<QPropertyAnimation> anim;
QRect currentAnimRect;
QRect startAnimRect;
QPoint mousePressOffset;
int lastIndex[2];
qreal animProgress;
FrameSvg *m_highlightSvg;
};
void NativeTabBarPrivate::syncBorders()
{
backgroundSvg->getMargins(left, top, right, bottom);
buttonSvg->getMargins(buttonLeft, buttonTop, buttonRight, buttonBottom);
}
void NativeTabBarPrivate::storeLastIndex()
{
// if first run, or invalid previous index
if (lastIndex[1] < 0 || lastIndex[1] >= q->count()) {
lastIndex[0] = q->currentIndex();
} else {
lastIndex[0] = lastIndex[1];
}
lastIndex[1] = q->currentIndex();
}
NativeTabBar::NativeTabBar(QWidget *parent)
: KTabBar(parent),
d(new NativeTabBarPrivate(this))
{
connect(this, SIGNAL(currentChanged(int)), this, SLOT(startAnimation()));
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
NativeTabBar::~NativeTabBar()
{
d->anim.clear();
delete d;
}
QRect NativeTabBar::tabRect(int index) const
{
QRect rect = KTabBar::tabRect(index).translated(d->left, d->top);
if (isVertical()) {
rect.setWidth(width() - d->left - d->right);
if (index == count() - 1) {
rect.adjust(0, 0, 0, -d->bottom);
}
} else {
rect.setHeight(height() - d->top- d->bottom);
if (index == count() - 1) {
rect.adjust(0, 0, -d->right, 0);
}
}
return rect;
}
int NativeTabBar::lastIndex() const
{
return d->lastIndex[0];
}
QSize NativeTabBar::tabSizeHint(int index) const
{
//return KTabBar::tabSizeHint(index);
QSize hint = tabSize(index);
int minwidth = 0;
int minheight = 0;
int maxwidth = 0;
Shape s = shape();
switch (s) {
case RoundedSouth:
case TriangularSouth:
case RoundedNorth:
case TriangularNorth:
if (count() > 0) {
for (int i = count() - 1; i >= 0; i--) {
minwidth += tabSize(i).width();
}
if (minwidth < width() - d->left - d->right) {
hint.rwidth() += (width() - d->left - d->right - minwidth) / count();
}
}
break;
case RoundedWest:
case TriangularWest:
case RoundedEast:
case TriangularEast:
if (count() > 0) {
for (int i = count() - 1; i >= 0; i--) {
minheight += tabSize(i).height();
if (tabSize(i).width() > maxwidth) {
maxwidth = tabSize(i).width();
}
}
if (minheight < height()) {
hint.rheight() += (height() - minheight) / count();
}
}
break;
}
return hint;
}
QSize NativeTabBar::sizeHint() const
{
return KTabBar::sizeHint();
}
void NativeTabBar::setTabHighlighted(int index, bool highlight)
{
if (index < 0 || index >= count()) {
return;
}
if (highlight != d->highlightedTabs[index]) {
d->highlightedTabs[index] = highlight;
update();
}
}
bool NativeTabBar::isTabHighlighted(int index) const
{
if (index < 0 || index >= count() ) {
return false;
}
return d->highlightedTabs[index];
}
void NativeTabBar::paintEvent(QPaintEvent *event)
{
if (!styleSheet().isNull()) {
KTabBar::paintEvent(event);
return;
}
QPainter painter(this);
//int numTabs = count();
//bool ltr = painter.layoutDirection() == Qt::LeftToRight; // Not yet used
if (drawBase()) {
d->backgroundSvg->paintFrame(&painter);
}
// Drawing Tabborders
QRect movingRect;
if (d->currentAnimRect.isNull() || !d->anim || d->anim.data()->state() != QAbstractAnimation::Running) {
movingRect = tabRect(currentIndex());
} else {
movingRect = d->currentAnimRect;
}
//resizing here because in resizeevent the first time is invalid (still no tabs)
d->buttonSvg->resizeFrame(movingRect.size());
d->buttonSvg->paintFrame(&painter, movingRect.topLeft());
QFontMetrics metrics(painter.font());
QRect scrollButtonsRect;
foreach (QObject *child, children()) {
QToolButton *childWidget = qobject_cast<QToolButton *>(child);
if (childWidget) {
if (!childWidget->isVisible()) {
continue;
}
if (scrollButtonsRect.isValid()) {
scrollButtonsRect = scrollButtonsRect.united(childWidget->geometry());
} else {
scrollButtonsRect = childWidget->geometry();
}
}
}
const QColor buttonText = Plasma::Theme::defaultTheme()->color(Theme::ButtonTextColor);
const QColor textColor = Plasma::Theme::defaultTheme()->color(Theme::TextColor);
const QColor highlightColor = Plasma::Theme::defaultTheme()->color(Theme::HighlightColor);
for (int i = 0; i < count(); ++i) {
const bool isHighlighted = d->highlightedTabs[i];
QRect rect = tabRect(i).adjusted(d->buttonLeft + buttonHMargin, d->buttonTop + buttonVMargin,
-(d->buttonRight + buttonHMargin), -(d->buttonBottom + buttonVMargin));
// draw tab icon
QRect iconRect = QRect(rect.x(), rect.y(), iconSize().width(), iconSize().height());
iconRect.moveCenter(QPoint(iconRect.center().x(), rect.center().y()));
if (!tabIcon(i).isNull()) {
if (isHighlighted) {
QRect iconRectAdjusted = iconRect.adjusted(-buttonHMargin, -buttonVMargin, buttonHMargin, buttonVMargin);
d->highlightSvg()->resizeFrame(iconRectAdjusted.size());
d->highlightSvg()->paintFrame(&painter, iconRectAdjusted.topLeft());
QPixmap iconPix = tabIcon(i).pixmap(iconRect.size());
KIconEffect *effect = KIconLoader::global()->iconEffect();
iconPix = effect->apply(iconPix, KIconLoader::Panel, KIconLoader::ActiveState);
painter.drawPixmap(iconRect.topLeft(), iconPix);
} else {
tabIcon(i).paint(&painter, iconRect);
painter.setOpacity(1.0);
}
}
// draw tab text
if (i == currentIndex() && d->animProgress == 1) {
painter.setPen(isHighlighted ? highlightColor : buttonText);
} else {
QColor color = (isHighlighted ? highlightColor : textColor);
if (!isTabEnabled(i)) {
color.setAlpha(140);
}
painter.setPen(color);
}
QRect textRect = rect;
if (!tabIcon(i).isNull()) {
textRect.setLeft(iconRect.right() + iconSpacing);
}
painter.setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
int endTabSpace = contentsRect().right() - scrollButtonsRect.width();
if (textRect.left() < endTabSpace) {
if (textRect.left() < contentsRect().left() || textRect.right() > endTabSpace) {
QPixmap buffer(textRect.size());
buffer.fill(Qt::transparent);
QPainter buffPainter(&buffer);
buffPainter.drawText(buffer.rect(), Qt::AlignCenter | Qt::TextHideMnemonic, tabText(i));
buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
QLinearGradient gradient(buffer.rect().topLeft(), buffer.rect().topRight());
if (textRect.left() < contentsRect().left()) {
gradient.setColorAt(0, Qt::transparent);
gradient.setColorAt(qBound(qreal(0), (-(qreal)textRect.left())/(qreal)textRect.width(), qreal(1)), Qt::transparent);
gradient.setColorAt(1, Qt::black);
} else {
gradient.setColorAt(0, Qt::black);
gradient.setColorAt(qBound(qreal(0), 1 - (qreal)(textRect.right() - endTabSpace)/(qreal)textRect.width(), qreal(1)), Qt::transparent);
gradient.setColorAt(1, Qt::transparent);
}
buffPainter.setBrush(gradient);
buffPainter.setPen(Qt::NoPen);
buffPainter.drawRect(buffer.rect());
buffPainter.end();
painter.drawPixmap(textRect, buffer, buffer.rect());
} else {
painter.drawText(textRect, Qt::AlignCenter | Qt::TextHideMnemonic, tabText(i));
}
}
}
if (scrollButtonsRect.isValid()) {
scrollButtonsRect.adjust(2, 4, -2, -4);
painter.save();
QColor background(Plasma::Theme::defaultTheme()->color(Theme::BackgroundColor));
background.setAlphaF(0.75);
painter.setRenderHint(QPainter::Antialiasing);
painter.fillPath(PaintUtils::roundedRectangle(scrollButtonsRect, 5), background);
painter.restore();
QStyleOption so;
so.initFrom(this);
so.palette.setColor(QPalette::ButtonText,
Plasma::Theme::defaultTheme()->color(Theme::TextColor));
so.rect = scrollButtonsRect.adjusted(0, 0, -scrollButtonsRect.width() / 2, 0);
style()->drawPrimitive(QStyle::PE_IndicatorArrowLeft, &so, &painter, this);
so.rect = scrollButtonsRect.adjusted(scrollButtonsRect.width() / 2, 0, 0, 0);
style()->drawPrimitive(QStyle::PE_IndicatorArrowRight, &so, &painter, this);
}
}
void NativeTabBar::resizeEvent(QResizeEvent *event)
{
KTabBar::resizeEvent(event);
d->currentAnimRect = tabRect(currentIndex());
d->backgroundSvg->resizeFrame(size());
d->syncBorders();
update();
}
void NativeTabBar::tabInserted(int index)
{
d->highlightedTabs.insert(index, false);
KTabBar::tabInserted(index);
emit sizeHintChanged();
d->currentAnimRect = tabRect(currentIndex());
d->backgroundSvg->resizeFrame(size());
d->syncBorders();
update();
}
void NativeTabBar::tabRemoved(int index)
{
d->highlightedTabs.removeAt(index);
KTabBar::tabRemoved(index);
emit sizeHintChanged();
d->currentAnimRect = tabRect(currentIndex());
d->backgroundSvg->resizeFrame(size());
d->syncBorders();
update();
}
void NativeTabBar::tabLayoutChange()
{
KTabBar::tabLayoutChange();
if (shape() != d->shape) {
d->shape = shape();
emit shapeChanged(d->shape);
}
}
void NativeTabBar::startAnimation()
{
d->storeLastIndex();
QPropertyAnimation *anim = d->anim.data();
if (anim) {
anim->stop();
d->anim.clear();
}
anim = new QPropertyAnimation(this, "onValueChanged", this);
d->anim = anim;
anim->setDuration(150);
QRect rect = tabRect(currentIndex());
QRect lastRect = d->startAnimRect.isNull() ? tabRect(lastIndex())
: d->startAnimRect;
int x = isHorizontal() ? (int)(lastRect.x() - (lastRect.x() - rect.x())) : rect.x();
int y = isHorizontal() ? rect.y() : (int)(lastRect.y() - (lastRect.y() - rect.y()));
QSizeF sz = lastRect.size() - (lastRect.size() - rect.size());
d->currentAnimRect = QRect(x, y, (int)(sz.width()), (int)(sz.height()));
anim->setStartValue(lastRect);
anim->setEndValue(d->currentAnimRect);
anim->start(QAbstractAnimation::DeleteWhenStopped);
}
void NativeTabBar::setOnValueChanged(QRectF value)
{
if (value == d->anim.data()->endValue()) {
d->animProgress = 1;
animationFinished();
return;
}
d->currentAnimRect = value.toRect();
update();
}
QRectF NativeTabBar::onValueChanged() const
{
return d->currentAnimRect;
}
void NativeTabBar::animationFinished()
{
d->startAnimRect = QRect();
d->currentAnimRect = QRect();
update();
}
bool NativeTabBar::isVertical() const
{
switch (shape()) {
case RoundedWest:
case RoundedEast:
case TriangularWest:
case TriangularEast:
return true;
break;
default:
break;
}
return false;
}
bool NativeTabBar::isHorizontal() const
{
return !isVertical();
}
QSize NativeTabBar::tabSize(int index) const
{
QSize hint;
const QFontMetrics metrics(QApplication::font());
const QSize textSize = metrics.size(Qt::TextHideMnemonic, tabText(index));
hint.rwidth() = textSize.width() + iconSpacing + iconSize().width() + buttonHMargin * 2;
hint.rheight() = qMax(iconSize().height(), textSize.height()) + buttonVMargin * 2;
hint.rwidth() += d->buttonLeft + d->buttonRight;
hint.rheight() += d->buttonTop + d->buttonBottom;
if (isVertical()) {
hint.rwidth() = qMax(hint.width(), int(minimumWidth() - d->left - d->right));
} else {
hint.rheight() = qMax(hint.height(), int(minimumHeight() - d->top - d->bottom));
}
return hint;
}
void NativeTabBar::mousePressEvent(QMouseEvent *event)
{
if (d->currentAnimRect.isNull()) {
QRect rect = tabRect(currentIndex());
if (rect.contains(event->pos())) {
d->mousePressOffset = event->pos();
event->accept();
return;
}
}
KTabBar::mousePressEvent(event);
}
void NativeTabBar::mouseMoveEvent(QMouseEvent *event)
{
if (d->mousePressOffset != QPoint()) {
d->currentAnimRect = tabRect(currentIndex());
if (isVertical()) {
int pos = qBound(0, d->currentAnimRect.top() + (event->pos().y() - d->mousePressOffset.y()),
height() - d->currentAnimRect.height());
d->currentAnimRect.moveTop(pos);
} else {
int pos = qBound(0, d->currentAnimRect.left() + (event->pos().x() - d->mousePressOffset.x()),
width() - d->currentAnimRect.width());
d->currentAnimRect.moveLeft(pos);
}
update();
} else {
KTabBar::mouseMoveEvent(event);
}
}
void NativeTabBar::mouseReleaseEvent(QMouseEvent *event)
{
if (d->mousePressOffset != QPoint()) {
int index = -1;
if (isVertical()) {
bool top = event->pos().y() - d->mousePressOffset.y() < 0;
index = tabAt(QPoint(1, top ? d->currentAnimRect.top() : d->currentAnimRect.bottom()));
} else {
bool left = event->pos().x() - d->mousePressOffset.x() < 0;
index = tabAt(QPoint(left ? d->currentAnimRect.left() : d->currentAnimRect.right(), 1));
}
d->mousePressOffset = QPoint();
if (index != currentIndex() && isTabEnabled(index)) {
d->startAnimRect = d->currentAnimRect;
setCurrentIndex(index);
} else {
d->currentAnimRect = QRect();
}
update();
} else {
KTabBar::mouseReleaseEvent(event);
}
}
void NativeTabBar::wheelEvent(QWheelEvent *event)
{
if (underMouse()) {
//Cycle tabs with the circular array tecnique
if (event->delta() < 0) {
int index = currentIndex();
//search for an enabled tab
for (int i = 0; i < count()-1; ++i) {
index = (index + 1) % count();
if (isTabEnabled(index)) {
break;
}
}
setCurrentIndex(index);
} else {
int index = currentIndex();
for (int i = 0; i < count()-1; ++i) {
index = (count() + index -1) % count();
if (isTabEnabled(index)) {
break;
}
}
setCurrentIndex(index);
}
} else {
QTabBar::wheelEvent(event);
}
}
} // namespace Plasma
#include "moc_nativetabbar_p.cpp"

View File

@ -1,98 +0,0 @@
/*
Copyright 2007 Robert Knight <robertknight@gmail.com>
Copyright 2008 Marco Martin <notmart@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef NATIVETABBAR_H
#define NATIVETABBAR_H
#include <ktabbar.h>
namespace Plasma
{
class NativeTabBarPrivate;
class NativeTabBar : public KTabBar
{
Q_OBJECT
Q_PROPERTY(QRectF onValueChanged READ onValueChanged WRITE setOnValueChanged)
public:
NativeTabBar(QWidget *parent = 0);
~NativeTabBar();
QRect tabRect(int index) const;
QSize tabSizeHint(int index) const;
QSize sizeHint() const;
/**
* Highlight the specified tab
* @param index of the tab to highlight
* @param highlight true if it should be highlighted, wrong if not
* @since 4.7
*/
void setTabHighlighted(int index, bool highlight);
/**
* @return if the tab at index is highlighted
* @since 4.7
*/
bool isTabHighlighted(int index) const;
protected:
int lastIndex() const;
// reimplemented from QTabBar
virtual void paintEvent(QPaintEvent *event);
virtual void resizeEvent(QResizeEvent *event);
void tabInserted(int index);
void tabRemoved(int index);
void tabLayoutChange();
bool isHorizontal() const;
bool isVertical() const;
void wheelEvent(QWheelEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
protected slots:
void animationFinished();
void startAnimation();
void setOnValueChanged(QRectF val);
QRectF onValueChanged() const;
Q_SIGNALS:
void sizeHintChanged();
void shapeChanged(QTabBar::Shape shape);
private:
QSize tabSize(int index) const;
NativeTabBarPrivate * const d;
friend class NativeTabBarPrivate;
Q_PRIVATE_SLOT(d, void syncBorders())
};
}
#endif // TABBAR_H

View File

@ -1,418 +0,0 @@
/*
* Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
* Copyright © 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "style_p.h"
#include <QPainter>
#include <QStyleOptionComplex>
#include <QSpinBox>
#include <QComboBox>
#include <QApplication>
#include <kdebug.h>
#include <plasma/framesvg.h>
#include <plasma/theme.h>
namespace Plasma {
class StylePrivate
{
public:
StylePrivate(Style *style)
: q(style),
scrollbar(0),
textBox(0)
{
}
~StylePrivate()
{
}
void createScrollbar()
{
if (!scrollbar) {
scrollbar = new Plasma::FrameSvg(q);
scrollbar->setImagePath("widgets/scrollbar");
scrollbar->setCacheAllRenderedFrames(true);
}
}
void createTextBox()
{
if (!textBox) {
textBox = new Plasma::FrameSvg(q);
textBox->setImagePath("widgets/lineedit");
textBox->setElementPrefix("base");
}
}
Style *q;
Plasma::FrameSvg *scrollbar;
Plasma::FrameSvg *textBox;
static Plasma::Style::Ptr s_sharedStyle;
};
Style::Ptr StylePrivate::s_sharedStyle(0);
Style::Ptr Style::sharedStyle()
{
if (!StylePrivate::s_sharedStyle) {
StylePrivate::s_sharedStyle = new Style();
}
return StylePrivate::s_sharedStyle;
}
void Style::doneWithSharedStyle()
{
if (StylePrivate::s_sharedStyle.isUnique()) {
StylePrivate::s_sharedStyle = 0;
}
}
Style::Style()
: QCommonStyle(),
d(new StylePrivate(this))
{
}
Style::~Style()
{
delete d;
}
void Style::drawComplexControl(ComplexControl control,
const QStyleOptionComplex *option,
QPainter *painter,
const QWidget *widget) const
{
if (Theme::defaultTheme()->useNativeWidgetStyle()) {
qApp->style()->drawComplexControl(control, option, painter, widget);
return;
}
switch (control) {
case CC_ScrollBar: {
d->createScrollbar();
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
const bool sunken = option->state & State_Sunken;
const QStyleOptionSlider *scrollOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
QString prefix;
if (option->state & State_MouseOver) {
prefix= "mouseover-";
}
QRect subLine;
QRect addLine;
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
subLine = d->scrollbar->elementRect(prefix + "arrow-left").toRect();
addLine = d->scrollbar->elementRect(prefix + "arrow-right").toRect();
} else {
subLine = d->scrollbar->elementRect(prefix + "arrow-up").toRect();
addLine = d->scrollbar->elementRect(prefix + "arrow-down").toRect();
}
subLine.moveCenter(subControlRect(control, option, SC_ScrollBarSubLine, widget).center());
addLine.moveCenter(subControlRect(control, option, SC_ScrollBarAddLine, widget).center());
QRect slider = subControlRect(control, option, SC_ScrollBarSlider, widget);
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
slider.adjust(0, 1, 0, -1);
} else {
slider.adjust(1, 0, -1, 0);
}
if (scrollOption && scrollOption->orientation == Qt::Horizontal && d->scrollbar->hasElement("background-horizontal-center")) {
d->scrollbar->setElementPrefix("background-horizontal");
} else if (scrollOption && scrollOption->orientation == Qt::Vertical && d->scrollbar->hasElement("background-vertical-center")) {
d->scrollbar->setElementPrefix("background-vertical");
} else {
d->scrollbar->setElementPrefix("background");
}
d->scrollbar->resizeFrame(option->rect.size());
d->scrollbar->paintFrame(painter);
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarSlider) {
d->scrollbar->setElementPrefix("sunken-slider");
} else {
d->scrollbar->setElementPrefix(prefix + "slider");
}
d->scrollbar->resizeFrame(slider.size());
d->scrollbar->paintFrame(painter, slider.topLeft());
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
if (sunken && scrollOption->activeSubControls & SC_ScrollBarAddLine) {
d->scrollbar->paint(painter, addLine, "sunken-arrow-right");
} else {
d->scrollbar->paint(painter, addLine, prefix + "arrow-right");
}
if (sunken && scrollOption->activeSubControls & SC_ScrollBarSubLine) {
d->scrollbar->paint(painter, subLine, "sunken-arrow-left");
} else {
d->scrollbar->paint(painter, subLine, prefix + "arrow-left");
}
} else {
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarAddLine) {
d->scrollbar->paint(painter, addLine, "sunken-arrow-down");
} else {
d->scrollbar->paint(painter, addLine, prefix + "arrow-down");
}
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarSubLine) {
d->scrollbar->paint(painter, subLine, "sunken-arrow-up");
} else {
d->scrollbar->paint(painter, subLine, prefix + "arrow-up");
}
}
painter->restore();
break;
}
case CC_SpinBox: {
d->createTextBox();
d->textBox->resizeFrame(option->rect.size());
d->textBox->paintFrame(painter);
const QStyleOptionSpinBox *spinOpt = qstyleoption_cast<const QStyleOptionSpinBox *>(option);
bool upSunken = (spinOpt->activeSubControls & SC_SpinBoxUp) &&
(spinOpt->state & (State_Sunken | State_On));
bool downSunken = (spinOpt->activeSubControls & SC_SpinBoxDown) &&
(spinOpt->state & (State_Sunken | State_On));
const QSpinBox *spin = qobject_cast<const QSpinBox *>(widget);
PrimitiveElement pe;
if (spin->buttonSymbols() == QSpinBox::PlusMinus) {
pe = PE_IndicatorSpinPlus;
} else {
pe = PE_IndicatorArrowUp;
}
QStyleOption upOpt;
upOpt = *option;
upOpt.rect = subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
if (upSunken) {
upOpt.state = State_Sunken|State_Enabled;
} else {
upOpt.state = State_Enabled;
}
qApp->style()->drawPrimitive(pe, &upOpt, painter, widget);
if (spin->buttonSymbols() == QSpinBox::PlusMinus) {
pe = PE_IndicatorSpinMinus;
} else {
pe = PE_IndicatorArrowDown;
}
QStyleOption downOpt;
downOpt= *option;
downOpt.rect = subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
if (downSunken) {
downOpt.state = State_Sunken|State_Enabled;
} else {
downOpt.state = State_Enabled;
}
qApp->style()->drawPrimitive(pe, &downOpt, painter, widget);
break;
}
case CC_ComboBox: {
const QComboBox *combo = qobject_cast<const QComboBox *>(widget);
if (!combo->isEditable()) {
qApp->style()->drawComplexControl(control, option, painter, widget);
} else {
d->createTextBox();
d->textBox->resizeFrame(option->rect.size());
d->textBox->paintFrame(painter);
QStyleOption arrowOpt;
arrowOpt = *option;
arrowOpt.rect = subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
qApp->style()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
}
break;
}
default:
qApp->style()->drawComplexControl(control, option, painter, widget);
}
}
void Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
if (Theme::defaultTheme()->useNativeWidgetStyle()) {
qApp->style()->drawPrimitive(element, option, painter, widget);
return;
}
switch (element) {
case PE_PanelLineEdit:
//comboboxes draws their own frame
if (qobject_cast<QComboBox *>(widget->parent())) {
return;
}
d->createTextBox();
d->textBox->resizeFrame(option->rect.size());
d->textBox->paintFrame(painter);
break;
default:
qApp->style()->drawPrimitive(element, option, painter, widget);
}
}
QRect Style::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
SubControl subControl, const QWidget *widget) const
{
QRect rect(QCommonStyle::subControlRect(control, option, subControl, widget));
switch (control) {
case CC_Slider: {
const QStyleOptionSlider *sliderOpt = qstyleoption_cast<const QStyleOptionSlider *>(option);
if (sliderOpt) {
if (sliderOpt->orientation == Qt::Horizontal) {
rect.moveCenter(QPoint(rect.center().x(), option->rect.center().y()));
} else {
rect.moveCenter(QPoint(option->rect.center().x(), rect.center().y()));
}
}
break;
}
case CC_ScrollBar: {
const bool hasButtons = d->scrollbar->hasElement("arrow-up");
switch (subControl) {
//If one of the arrows is missing, don't reserve space for them
case SC_ScrollBarAddLine:
if (!hasButtons) {
rect.setRect(0,0,0,0);
}
break;
case SC_ScrollBarSubLine:
if (!hasButtons) {
rect.setRect(0,0,0,0);
}
break;
default:
break;
}
}
default:
break;
}
return rect;
}
int Style::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const
{
switch (hint) {
case SH_RequestSoftwareInputPanel:
return RSIP_OnMouseClick;
default:
return QCommonStyle::styleHint(hint, option, widget, returnData);
}
}
int Style::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
{
if (Theme::defaultTheme()->useNativeWidgetStyle()) {
return qApp->style()->pixelMetric(metric, option, widget);
}
switch (metric) {
case PM_ScrollBarExtent: {
d->createScrollbar();
const QSizeF hintSize = d->scrollbar->elementSize("hint-scrollbar-size");
const QStyleOptionSlider *scrollOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
if (scrollOption && scrollOption->orientation == Qt::Vertical) {
if (hintSize.isEmpty()) {
return d->scrollbar->elementSize("arrow-down").width() + 2;
} else {
return hintSize.width();
}
} else {
if (hintSize.isEmpty()) {
return d->scrollbar->elementSize("arrow-left").height() + 2;
} else {
return hintSize.height();
}
}
}
default:
return qApp->style()->pixelMetric(metric, option, widget);
}
}
QRect Style::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
{
switch (element) {
case SE_LineEditContents: {
d->createTextBox();
qreal left, top, right, bottom;
d->textBox->getMargins(left, top, right, bottom);
return option->rect.adjusted(left + 2, top + 2, -(right + 2), -(bottom + 2));
}
default:
return qApp->style()->subElementRect(element, option, widget);
}
}
QSize Style::sizeFromContents(ContentsType type, const QStyleOption *option,
const QSize &contentsSize, const QWidget *widget) const
{
switch (type) {
case CT_SpinBox: {
d->createTextBox();
qreal left, top, right, bottom;
d->textBox->getMargins(left, top, right, bottom);
return contentsSize + QSize(left + right - 2, top + bottom - 2);
}
case CT_LineEdit: {
d->createTextBox();
qreal left, top, right, bottom;
d->textBox->getMargins(left, top, right, bottom);
return contentsSize + QSize(left + right + 4, top + bottom + 4);
}
default:
return qApp->style()->sizeFromContents(type, option, contentsSize, widget);
}
}
}
#include "moc_style_p.cpp"

View File

@ -1,69 +0,0 @@
/*
* Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
* Copyright © 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_STYLE_P_H
#define PLASMA_STYLE_P_H
#include <QtCore/QSharedData>
#include <QCommonStyle>
#include <ksharedptr.h>
namespace Plasma
{
class StylePrivate;
class Style : public QCommonStyle, public QSharedData
{
Q_OBJECT
public:
typedef KSharedPtr<Style> Ptr;
static Style::Ptr sharedStyle();
static void doneWithSharedStyle();
explicit Style();
~Style();
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = 0) const;
int styleHint(StyleHint hint, const QStyleOption *option=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const;
protected:
void drawComplexControl(ComplexControl control,
const QStyleOptionComplex *option,
QPainter *painter,
const QWidget *widget) const;
int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const;
QRect subControlRect(ComplexControl control, const QStyleOptionComplex *option,
SubControl subControl, const QWidget *widget) const;
QRect subElementRect(SubElement element, const QStyleOption * option, const QWidget *widget = 0) const;
QSize sizeFromContents(ContentsType, const QStyleOption *option, const QSize &contentsSize,
const QWidget *widget = 0) const;
private:
StylePrivate *d;
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,222 +0,0 @@
/*
* Copyright 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "busywidget.h"
//Qt
#include <QPainter>
#include <QTimer>
#include <QGraphicsSceneResizeEvent>
#include <QTextOption>
//Plasma
#include "plasma/theme.h"
#include "plasma/svg.h"
namespace Plasma
{
class BusyWidgetPrivate
{
public:
BusyWidgetPrivate()
: svg(0),
timerId(0),
rotationAngle(0),
rotation(0),
running(true)
{
}
~BusyWidgetPrivate()
{
}
void themeChanged()
{
frames.clear();
rotationAngle = svg->elementSize("hint-rotation-angle").width();
//use an angle near to rotationAngle but that it fits an integer number of times in 360
int nFrames = 360/rotationAngle;
rotationAngle = 360/nFrames;
}
Svg *svg;
QString styleSheet;
int timerId;
QHash<int, QPixmap> frames;
qreal rotationAngle;
qreal rotation;
bool running;
QString label;
};
BusyWidget::BusyWidget(QGraphicsWidget *parent)
: QGraphicsWidget(parent),
d(new BusyWidgetPrivate)
{
d->svg = new Plasma::Svg(this);
d->svg->setImagePath("widgets/busywidget");
d->svg->setContainsMultipleImages(true);
d->themeChanged();
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(themeChanged()));
}
BusyWidget::~BusyWidget()
{
delete d;
}
void BusyWidget::setRunning(bool running)
{
if (running && !d->timerId && isVisible()) {
d->timerId = startTimer(150);
} else if (!running && d->timerId) {
killTimer(d->timerId);
d->timerId = 0;
}
d->running = running;
}
bool BusyWidget::isRunning() const
{
return d->running;
}
void BusyWidget::setLabel(const QString &label)
{
d->label = label;
update();
}
QString BusyWidget::label() const
{
return d->label;
}
void BusyWidget::timerEvent(QTimerEvent *event)
{
if (event->timerId() != d->timerId) {
QObject::timerEvent(event);
return;
}
d->rotation += d->rotationAngle;
qreal overflow = d->rotation - 360;
if ( overflow > 0) {
d->rotation = overflow;
}
update();
}
void BusyWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
int intRotation = int(d->rotation);
QRectF spinnerRect(QPoint(0, 0), QSize(qMin(size().width(), size().height()), qMin(size().width(), size().height())));
spinnerRect.moveCenter(boundingRect().center());
if (!isEnabled()) {
painter->setOpacity(painter->opacity() / 2);
}
if (!d->running && d->svg->hasElement("paused")) {
d->svg->paint(painter, spinnerRect, "paused");
} else {
if (!d->frames[intRotation]) {
QPointF translatedPos(spinnerRect.width()/2, spinnerRect.height()/2);
d->frames[intRotation] = QPixmap(spinnerRect.size().toSize());
d->frames[intRotation].fill(Qt::transparent);
QPainter buffPainter(&d->frames[intRotation]);
buffPainter.setRenderHints(QPainter::SmoothPixmapTransform);
buffPainter.translate(translatedPos);
if (d->svg->hasElement("busywidget-shadow")) {
buffPainter.save();
buffPainter.translate(1,1);
buffPainter.rotate(intRotation);
d->svg->paint(&buffPainter, QRectF(-translatedPos.toPoint(), spinnerRect.size()), "busywidget-shadow");
buffPainter.restore();
}
buffPainter.rotate(intRotation);
d->svg->paint(&buffPainter, QRectF(-translatedPos.toPoint(), spinnerRect.size()), "busywidget");
}
painter->drawPixmap(spinnerRect.topLeft().toPoint(), d->frames[intRotation]);
}
painter->setPen(Plasma::Theme::defaultTheme()->color(Theme::TextColor));
Qt::Alignment align(Qt::AlignVCenter | Qt::AlignHCenter);
painter->drawText(boundingRect(), d->label, QTextOption(align));
}
void BusyWidget::showEvent(QShowEvent *event)
{
Q_UNUSED(event)
if (d->running) {
d->timerId = startTimer(150);
}
}
void BusyWidget::hideEvent(QHideEvent *event)
{
Q_UNUSED(event)
if (d->timerId) {
killTimer(d->timerId);
}
d->timerId = 0;
}
void BusyWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
{
Q_UNUSED(event)
d->frames.clear();
}
void BusyWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->setAccepted(true);
}
void BusyWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if ((event->button() & Qt::LeftButton) ||
(event->buttons() & Qt::LeftButton)) {
emit clicked();
}
}
} // namespace Plasma
#include "moc_busywidget.cpp"

View File

@ -1,102 +0,0 @@
/*
* Copyright 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_BUSYWIDGET_H
#define PLASMA_BUSYWIDGET_H
#include <QGraphicsWidget>
#include <plasma/plasma_export.h>
class QFrame;
namespace Plasma
{
class BusyWidgetPrivate;
/**
* @class BusyWidget plasma/widgets/spinner.h <Plasma/Widgets/BusyWidget>
*
* @short A widget that provides a waiting spinner
*
* A simple spinner widget that can be used to represent a wait of unknown length
*/
class PLASMA_EXPORT BusyWidget : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(bool running READ isRunning WRITE setRunning)
Q_PROPERTY(QString label READ label WRITE setLabel)
public:
/**
* Constructs a new BusyWidget
*
* @param parent the parent of this widget
*/
explicit BusyWidget(QGraphicsWidget *parent = 0);
~BusyWidget();
/**
* @param running whether or not the spinner has to be animated. defaults to true.
*/
void setRunning(bool running);
/**
* @return whether or not the spinner is animated.
*/
bool isRunning() const;
/**
* @param label a string to be shown in front of the icon.
*/
void setLabel(const QString &label);
/**
* @param label the string that is shown in front of the icon.
*/
QString label() const;
Q_SIGNALS:
void clicked();
protected:
void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget = 0);
void showEvent(QShowEvent *event);
void hideEvent(QHideEvent *event);
void resizeEvent(QGraphicsSceneResizeEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
protected Q_SLOTS:
void timerEvent(QTimerEvent *event);
private:
BusyWidgetPrivate * const d;
Q_PRIVATE_SLOT(d, void themeChanged())
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,188 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "checkbox.h"
#include <QCheckBox>
#include <QPainter>
#include <QDir>
#include <qmimedatabase.h>
#include "private/themedwidgetinterface_p.h"
#include "svg.h"
#include "theme.h"
namespace Plasma
{
class CheckBoxPrivate : public ThemedWidgetInterface<CheckBox>
{
public:
CheckBoxPrivate(CheckBox *c)
: ThemedWidgetInterface<CheckBox>(c),
svg(0)
{
}
~CheckBoxPrivate()
{
delete svg;
}
void setPixmap()
{
if (imagePath.isEmpty()) {
delete svg;
svg = 0;
return;
}
QMimeDatabase db;
QMimeType mime = db.mimeTypeForFile(absImagePath);
QPixmap pm(q->size().toSize());
if (mime.inherits("image/svg+xml") || mime.inherits("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != imagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
}
QPainter p(&pm);
svg->paint(&p, pm.rect());
} else {
delete svg;
svg = 0;
pm = QPixmap(absImagePath);
}
static_cast<QCheckBox*>(q->widget())->setIcon(QIcon(pm));
}
QString imagePath;
QString absImagePath;
Svg *svg;
};
CheckBox::CheckBox(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new CheckBoxPrivate(this))
{
QCheckBox *native = new QCheckBox;
connect(native, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
d->setWidget(native);
native->setWindowIcon(QIcon());
native->setAttribute(Qt::WA_NoSystemBackground);
d->initTheming();
}
CheckBox::~CheckBox()
{
delete d;
}
void CheckBox::setText(const QString &text)
{
static_cast<QCheckBox*>(widget())->setText(text);
}
QString CheckBox::text() const
{
return static_cast<QCheckBox*>(widget())->text();
}
void CheckBox::setImage(const QString &path)
{
if (d->imagePath == path) {
return;
}
delete d->svg;
d->svg = 0;
d->imagePath = path;
bool absolutePath = !path.isEmpty() &&
#ifdef Q_OS_WIN
!QDir::isRelativePath(path)
#else
(path[0] == '/' || path.startsWith(QLatin1String(":/")))
#endif
;
if (absolutePath) {
d->absImagePath = path;
} else {
//TODO: package support
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap();
}
QString CheckBox::image() const
{
return d->imagePath;
}
void CheckBox::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString CheckBox::styleSheet()
{
return widget()->styleSheet();
}
QCheckBox *CheckBox::nativeWidget() const
{
return static_cast<QCheckBox*>(widget());
}
void CheckBox::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap();
QGraphicsProxyWidget::resizeEvent(event);
}
void CheckBox::setChecked(bool checked)
{
static_cast<QCheckBox*>(widget())->setChecked(checked);
}
bool CheckBox::isChecked() const
{
return static_cast<QCheckBox*>(widget())->isChecked();
}
void CheckBox::changeEvent(QEvent *event)
{
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include "moc_checkbox.cpp"

View File

@ -1,123 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_CHECKBOX_H
#define PLASMA_CHECKBOX_H
#include <QGraphicsProxyWidget>
#include <plasma/plasma_export.h>
class QCheckBox;
namespace Plasma
{
class CheckBoxPrivate;
/**
* @class CheckBox plasma/widgets/checkbox.h <Plasma/Widgets/CheckBox>
*
* @short Provides a Plasma-themed checkbox.
*/
class PLASMA_EXPORT CheckBox : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(QCheckBox *nativeWidget READ nativeWidget)
Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
public:
explicit CheckBox(QGraphicsWidget *parent = 0);
~CheckBox();
/**
* Sets the display text for this CheckBox
*
* @param text the text to display; should be translated.
*/
void setText(const QString &text);
/**
* @return the display text
*/
QString text() const;
/**
* Sets the path to an image to display.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
*/
void setImage(const QString &path);
/**
* @return the image path being displayed currently, or an empty string if none.
*/
QString image() const;
/**
* Sets the stylesheet used to control the visual display of this CheckBox
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* @return the native widget wrapped by this CheckBox
*/
QCheckBox *nativeWidget() const;
/**
* Sets the checked state.
*
* @param checked true if checked, false if not
*/
void setChecked(bool checked);
/**
* @return the checked state
*/
bool isChecked() const;
Q_SIGNALS:
void toggled(bool);
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event);
private:
Q_PRIVATE_SLOT(d, void setPalette())
Q_PRIVATE_SLOT(d, void setPixmap())
CheckBoxPrivate * const d;
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,356 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "combobox.h"
#include <QPainter>
#include <QGraphicsView>
#include <kcombobox.h>
#include <kiconeffect.h>
#include <kiconloader.h>
#include "applet.h"
#include "framesvg.h"
#include "graphicsview/private/style_p.h"
#include "graphicsview/private/focusindicator_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
class ComboBoxPrivate : public ThemedWidgetInterface<ComboBox>
{
public:
ComboBoxPrivate(ComboBox *comboBox)
: ThemedWidgetInterface<ComboBox>(comboBox),
background(0),
underMouse(false)
{
}
~ComboBoxPrivate()
{
}
void syncActiveRect();
void syncBorders();
FrameSvg *background;
FrameSvg *lineEditBackground;
FocusIndicator *focusIndicator;
int animId;
qreal opacity;
QRectF activeRect;
Style::Ptr style;
bool underMouse;
};
void ComboBoxPrivate::syncActiveRect()
{
background->setElementPrefix("normal");
qreal left, top, right, bottom;
background->getMargins(left, top, right, bottom);
background->setElementPrefix("active");
qreal activeLeft, activeTop, activeRight, activeBottom;
background->getMargins(activeLeft, activeTop, activeRight, activeBottom);
activeRect = QRectF(QPointF(0, 0), q->size());
activeRect.adjust(left - activeLeft, top - activeTop,
-(right - activeRight), -(bottom - activeBottom));
background->setElementPrefix("normal");
}
void ComboBoxPrivate::syncBorders()
{
//set margins from the normal element
qreal left, top, right, bottom;
background->setElementPrefix("normal");
background->getMargins(left, top, right, bottom);
q->setContentsMargins(left, top, right, bottom);
//calc the rect for the over effect
syncActiveRect();
if (customFont) {
q->setFont(q->font());
} else {
q->setFont(Theme::defaultTheme()->font(Theme::DefaultFont));
customFont = false;
}
if (q->nativeWidget()->isEditable()) {
focusIndicator->setFrameSvg(lineEditBackground);
} else {
focusIndicator->setFrameSvg(background);
}
focusIndicator->setFlag(QGraphicsItem::ItemStacksBehindParent, !q->nativeWidget()->isEditable() || !lineEditBackground->hasElement("hint-focus-over-base"));
}
ComboBox::ComboBox(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new ComboBoxPrivate(this))
{
d->background = new FrameSvg(this);
d->background->setImagePath("widgets/button");
d->background->setCacheAllRenderedFrames(true);
d->background->setElementPrefix("normal");
d->lineEditBackground = new FrameSvg(this);
d->lineEditBackground->setImagePath("widgets/lineedit");
d->lineEditBackground->setCacheAllRenderedFrames(true);
setZValue(900);
setAcceptHoverEvents(true);
d->style = Style::sharedStyle();
d->focusIndicator = new FocusIndicator(this, d->background);
setNativeWidget(new KComboBox);
connect(d->background, SIGNAL(repaintNeeded()), SLOT(syncBorders()));
d->initTheming();
}
ComboBox::~ComboBox()
{
delete d;
Style::doneWithSharedStyle();
}
QString ComboBox::text() const
{
return static_cast<KComboBox*>(widget())->currentText();
}
void ComboBox::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString ComboBox::styleSheet()
{
return widget()->styleSheet();
}
void ComboBox::setNativeWidget(KComboBox *nativeWidget)
{
if (widget()) {
widget()->deleteLater();
}
connect(nativeWidget, SIGNAL(activated(QString)), this, SIGNAL(activated(QString)));
connect(nativeWidget, SIGNAL(currentIndexChanged(int)),
this, SIGNAL(currentIndexChanged(int)));
connect(nativeWidget, SIGNAL(currentIndexChanged(QString)),
this, SIGNAL(textChanged(QString)));
d->setWidget(nativeWidget);
nativeWidget->setWindowIcon(QIcon());
nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
nativeWidget->setStyle(d->style.data());
d->syncBorders();
}
KComboBox *ComboBox::nativeWidget() const
{
return static_cast<KComboBox*>(widget());
}
void ComboBox::addItem(const QString &text)
{
static_cast<KComboBox*>(widget())->addItem(text);
}
void ComboBox::clear()
{
static_cast<KComboBox*>(widget())->clear();
}
void ComboBox::resizeEvent(QGraphicsSceneResizeEvent *event)
{
if (d->background) {
//resize needed panels
d->syncActiveRect();
d->background->setElementPrefix("focus");
d->background->resizeFrame(size());
d->background->setElementPrefix("active");
d->background->resizeFrame(d->activeRect.size());
d->background->setElementPrefix("normal");
d->background->resizeFrame(size());
}
QGraphicsProxyWidget::resizeEvent(event);
}
void ComboBox::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
if (!styleSheet().isNull() ||
Theme::defaultTheme()->useNativeWidgetStyle()) {
QGraphicsProxyWidget::paint(painter, option, widget);
return;
}
if (nativeWidget()->isEditable()) {
QGraphicsProxyWidget::paint(painter, option, widget);
return;
}
QPixmap bufferPixmap;
//normal button
if (isEnabled()) {
d->background->setElementPrefix("normal");
d->background->paintFrame(painter);
//disabled widget
} else {
bufferPixmap = QPixmap(rect().size().toSize());
bufferPixmap.fill(Qt::transparent);
QPainter buffPainter(&bufferPixmap);
d->background->paintFrame(&buffPainter);
buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
buffPainter.fillRect(bufferPixmap.rect(), QColor(0, 0, 0, 128));
painter->drawPixmap(0, 0, bufferPixmap);
}
painter->setPen(Theme::defaultTheme()->color(Theme::ButtonTextColor));
QStyleOptionComboBox comboOpt;
comboOpt.initFrom(nativeWidget());
comboOpt.palette.setColor(
QPalette::ButtonText, Theme::defaultTheme()->color(Theme::ButtonTextColor));
comboOpt.currentIcon = nativeWidget()->itemIcon(
nativeWidget()->currentIndex());
comboOpt.currentText = nativeWidget()->itemText(
nativeWidget()->currentIndex());
comboOpt.editable = false;
nativeWidget()->style()->drawControl(
QStyle::CE_ComboBoxLabel, &comboOpt, painter, nativeWidget());
comboOpt.rect = nativeWidget()->style()->subControlRect(
QStyle::CC_ComboBox, &comboOpt, QStyle::SC_ComboBoxArrow, nativeWidget());
nativeWidget()->style()->drawPrimitive(
QStyle::PE_IndicatorArrowDown, &comboOpt, painter, nativeWidget());
}
void ComboBox::focusInEvent(QFocusEvent *event)
{
QGraphicsProxyWidget::focusInEvent(event);
}
void ComboBox::focusOutEvent(QFocusEvent *event)
{
QGraphicsWidget *widget = parentWidget();
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
while (!applet && widget) {
widget = widget->parentWidget();
applet = qobject_cast<Plasma::Applet *>(widget);
}
if (applet) {
applet->setStatus(Plasma::UnknownStatus);
}
if (nativeWidget()->isEditable()) {
QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
if (qApp) {
if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
if (view->scene() && view->scene() == scene()) {
QApplication::sendEvent(view, &closeEvent);
}
}
}
}
QGraphicsProxyWidget::focusOutEvent(event);
}
void ComboBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
d->underMouse = true;
QGraphicsProxyWidget::hoverEnterEvent(event);
}
void ComboBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
d->underMouse = false;
QGraphicsProxyWidget::hoverLeaveEvent(event);
}
void ComboBox::changeEvent(QEvent *event)
{
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}
void ComboBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsWidget *widget = parentWidget();
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
while (!applet && widget) {
widget = widget->parentWidget();
applet = qobject_cast<Plasma::Applet *>(widget);
}
if (applet) {
applet->setStatus(Plasma::AcceptingInputStatus);
}
QGraphicsProxyWidget::mousePressEvent(event);
}
int ComboBox::count() const
{
return nativeWidget()->count();
}
int ComboBox::currentIndex() const
{
return nativeWidget()->currentIndex();
}
void ComboBox::setCurrentIndex(int index)
{
nativeWidget()->setCurrentIndex(index);
}
} // namespace Plasma
#include "moc_combobox.cpp"

View File

@ -1,154 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_COMBOBOX_H
#define PLASMA_COMBOBOX_H
#include <QGraphicsProxyWidget>
class KComboBox;
#include <plasma/plasma_export.h>
namespace Plasma
{
class ComboBoxPrivate;
/**
* @class ComboBox plasma/widgets/combobox.h <Plasma/Widgets/ComboBox>
*
* @short Provides a Plasma-themed combo box.
*/
class PLASMA_EXPORT ComboBox : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text NOTIFY textChanged)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(KComboBox *nativeWidget READ nativeWidget WRITE setNativeWidget)
Q_PROPERTY(int count READ count)
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
public:
explicit ComboBox(QGraphicsWidget *parent = 0);
~ComboBox();
/**
* @return the display text
*/
QString text() const;
/**
* Sets the stylesheet used to control the visual display of this ComboBox
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* Sets the combo box wrapped by this ComboBox (widget must inherit KComboBox), ownership is transferred to the ComboBox
*
* @param nativeWidget combo box that will be wrapped by this ComboBox
* @since KDE4.4
*/
void setNativeWidget(KComboBox *nativeWidget);
/**
* @return the native widget wrapped by this ComboBox
*/
KComboBox *nativeWidget() const;
/**
* Adds an item to the combo box with the given text. The
* item is appended to the list of existing items.
*/
Q_INVOKABLE void addItem(const QString &text);
/**
* Returns the number of items in the combo box
* @since 4.6
*/
int count() const;
/**
* Returns the current index of the combobox
* @since 4.6
*/
int currentIndex() const;
/**
* Sets the current index of the combobox
* @since 4.6
*/
void setCurrentIndex(int index);
public Q_SLOTS:
void clear();
Q_SIGNALS:
/**
* This signal is sent when the user chooses an item in the combobox.
* The item's text is passed.
*/
void activated(const QString &text);
/**
* This signal is sent whenever the currentIndex in the combobox changes
* either through user interaction or programmatically.
* The item's text is passed.
*/
void textChanged(const QString &text);
/**
* This signal is sent whenever the currentIndex in the combobox changes
* either through user interaction or programmatically.
*/
void currentIndexChanged(int index);
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget);
void focusInEvent(QFocusEvent *event);
void focusOutEvent(QFocusEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void changeEvent(QEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
private:
ComboBoxPrivate * const d;
friend class ComboBoxPrivate;
Q_PRIVATE_SLOT(d, void syncBorders())
Q_PRIVATE_SLOT(d, void setPalette())
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,333 +0,0 @@
/*
* Copyright 2007 by André Duffeck <duffeck@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Stre
* et, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "flashinglabel.h"
#include <QtCore/QString>
#include <QtCore/QTimeLine>
#include <QtCore/QTimer>
#include <QtCore/QWeakPointer>
#include <QPainter>
#include <QPixmap>
#include <QColor>
#include <kdebug.h>
#include <plasma/animator.h>
#include <plasma/animations/animation.h>
#include <plasma/theme.h>
using namespace Plasma;
class Plasma::FlashingLabelPrivate
{
public:
enum FlashingLabelType {
Text,
Pixmap
};
enum State {
Visible,
Invisible
};
FlashingLabelPrivate(FlashingLabel *flash)
: q(flash),
defaultDuration(3000),
type(FlashingLabelPrivate::Text),
color(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor)),
state(FlashingLabelPrivate::Invisible),
autohide(false)
{
fadeOutTimer.setInterval(defaultDuration);
fadeOutTimer.setSingleShot(true);
fadeInTimer.setInterval(0);
fadeInTimer.setSingleShot(true);
QObject::connect(Theme::defaultTheme(), SIGNAL(themeChanged()), q, SLOT(setPalette()));
}
~FlashingLabelPrivate() { }
void renderPixmap(const QSize &size);
void setupFlash(int duration);
void elementAnimationFinished();
void setPalette();
FlashingLabel *q;
int defaultDuration;
FlashingLabelType type;
QTimer fadeInTimer;
QTimer fadeOutTimer;
QString text;
QColor color;
QFont font;
QPixmap pixmap;
QWeakPointer<Plasma::Animation> anim;
QPixmap renderedPixmap;
QTextOption textOption;
Qt::Alignment alignment;
State state;
bool autohide;
};
FlashingLabel::FlashingLabel(QGraphicsItem *parent)
: QGraphicsWidget(parent),
d(new FlashingLabelPrivate(this))
{
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
setCacheMode(NoCache);
connect(&d->fadeOutTimer, SIGNAL(timeout()), this, SLOT(fadeOut()));
connect(&d->fadeInTimer, SIGNAL(timeout()), this, SLOT(fadeIn()));
}
FlashingLabel::~FlashingLabel()
{
delete d;
}
int FlashingLabel::duration() const
{
return d->defaultDuration;
}
void FlashingLabel::setDuration(int duration)
{
if (duration < 1) {
return;
}
d->defaultDuration = duration;
}
QColor FlashingLabel::color() const
{
return d->color;
}
void FlashingLabel::setColor(const QColor &color)
{
d->color = color;
}
QFont FlashingLabel::font() const
{
return d->font;
}
void FlashingLabel::setFont(const QFont &font)
{
d->font = font;
}
void FlashingLabel::flash(const QString &text, int duration, const QTextOption &option)
{
if (text.isEmpty()) {
return;
}
//kDebug() << duration << text;
d->type = FlashingLabelPrivate::Text;
d->text = text;
d->textOption = option;
d->setupFlash(duration);
}
void FlashingLabel::flash(const QPixmap &pixmap, int duration, Qt::Alignment align)
{
if (pixmap.isNull()) {
return;
}
d->type = FlashingLabelPrivate::Pixmap;
d->pixmap = pixmap;
d->alignment = align;
d->setupFlash(duration);
}
void FlashingLabel::setAutohide(bool autohide)
{
d->autohide = autohide;
if (autohide) {
if (d->anim.data()) {
connect(d->anim.data(), SIGNAL(finished()), this, SLOT(elementAnimationFinished()));
}
} else if (d->anim.data()) {
disconnect(d->anim.data(), SIGNAL(finished()), this, SLOT(elementAnimationFinished()));
}
}
bool FlashingLabel::autohide() const
{
return d->autohide;
}
void FlashingLabel::kill()
{
d->fadeInTimer.stop();
if (d->state == FlashingLabelPrivate::Visible) {
fadeOut();
}
}
void FlashingLabel::fadeIn()
{
//kDebug();
if (d->autohide) {
show();
}
d->state = FlashingLabelPrivate::Visible;
if (!d->anim.data()) {
d->anim = Plasma::Animator::create(Plasma::Animator::PixmapTransitionAnimation);
Plasma::Animation *animation = d->anim.data();
animation->setProperty("startPixmap", d->renderedPixmap);
animation->setTargetWidget(this);
animation->start();
} else {
Plasma::Animation *animation = d->anim.data();
if (animation->state() == QAbstractAnimation::Running) {
animation->stop();
animation->start();
}
}
}
void FlashingLabel::fadeOut()
{
if (d->state == FlashingLabelPrivate::Invisible) {
return; // FlashingLabel was already killed - do not animate again
}
d->state = FlashingLabelPrivate::Invisible;
if (d->anim.data()) {
Plasma::Animation *animation = d->anim.data();
animation->setProperty("direction", QAbstractAnimation::Backward);
animation->start(QAbstractAnimation::DeleteWhenStopped);
} else {
d->anim = Plasma::Animator::create(Plasma::Animator::PixmapTransitionAnimation);
Plasma::Animation *animation = d->anim.data();
animation->setProperty("direction", QAbstractAnimation::Backward);
animation->setProperty("startPixmap", d->renderedPixmap);
animation->setTargetWidget(this);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
}
void FlashingLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
if (d->anim.data() && d->anim.data()->state() == QAbstractAnimation::Running) {
Plasma::Animation *animation = d->anim.data();
painter->drawPixmap(0, 0, qvariant_cast<QPixmap>(animation->property("currentPixmap")));
} else if (d->state == FlashingLabelPrivate::Visible) {
painter->drawPixmap(0, 0, d->renderedPixmap);
}
}
QSizeF FlashingLabel::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
if (which == Qt::PreferredSize) {
QFontMetrics fm(d->font);
return fm.boundingRect(d->text).size();
}
return QGraphicsWidget::sizeHint(which, constraint);
}
void FlashingLabelPrivate::renderPixmap(const QSize &size)
{
if (renderedPixmap.size() != size) {
renderedPixmap = QPixmap(size);
}
renderedPixmap.fill(Qt::transparent);
QPainter painter(&renderedPixmap);
if (type == FlashingLabelPrivate::Text) {
painter.setPen(color);
painter.setFont(font);
painter.drawText(QRect(QPoint(0, 0), size), text, textOption);
} else if (type == FlashingLabelPrivate::Pixmap) {
QPoint p;
if(alignment & Qt::AlignLeft) {
p.setX(0);
} else if (alignment & Qt::AlignRight) {
p.setX(size.width() - pixmap.width());
} else {
p.setX((size.width() - pixmap.width()) / 2);
}
if (alignment & Qt::AlignTop) {
p.setY(0);
} else if (alignment & Qt::AlignRight) {
p.setY(size.height() - pixmap.height());
} else {
p.setY((size.height() - pixmap.height()) / 2);
}
painter.drawPixmap(p, pixmap);
}
painter.end();
if (anim.data()) {
Plasma::Animation *animation = anim.data();
animation->setProperty("startPixmap", renderedPixmap);
}
}
void FlashingLabelPrivate::setupFlash(int duration)
{
fadeOutTimer.stop();
fadeOutTimer.setInterval(duration > 0 ? duration : defaultDuration);
renderPixmap(q->size().toSize());
if (state != FlashingLabelPrivate::Visible) {
fadeInTimer.start();
} else {
q->update();
}
if (fadeOutTimer.interval() > 0) {
fadeOutTimer.start();
}
}
void FlashingLabelPrivate::elementAnimationFinished()
{
if (autohide && state == FlashingLabelPrivate::Invisible && anim.data()) {
q->hide();
}
}
void FlashingLabelPrivate::setPalette()
{
color = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
q->update();
}
#include "moc_flashinglabel.cpp"

View File

@ -1,88 +0,0 @@
/*
* Copyright 2007 by André Duffeck <duffeck@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_FLASHINGLABEL_H
#define PLASMA_FLASHINGLABEL_H
#include <QGraphicsWidget>
#include <QTextOption>
#include <plasma/plasma_export.h>
namespace Plasma
{
class FlashingLabelPrivate;
/**
* @class FlashingLabel plasma/widgets/flashinglabel.h <Plasma/Widgets/FlashingLabel>
*
* @short Provides flashing text or icons inside Plasma
*/
class PLASMA_EXPORT FlashingLabel : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(bool autohide READ autohide WRITE setAutohide)
Q_PROPERTY(QFont font READ font WRITE setFont)
Q_PROPERTY(QColor color READ color WRITE setColor)
Q_PROPERTY(int duration READ duration WRITE setDuration)
public:
explicit FlashingLabel(QGraphicsItem *parent = 0);
virtual ~FlashingLabel();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
QFont font() const;
void setFont(const QFont &);
QColor color() const;
void setColor(const QColor &);
int duration() const;
void setDuration(int duration);
Q_INVOKABLE void flash(const QString &text, int duration = 0,
const QTextOption &option = QTextOption(Qt::AlignCenter));
Q_INVOKABLE void flash(const QPixmap &pixmap, int duration = 0,
Qt::Alignment align = Qt::AlignCenter);
void setAutohide(bool autohide);
bool autohide() const;
protected:
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
public Q_SLOTS:
void kill();
protected Q_SLOTS:
void fadeIn();
void fadeOut();
private:
Q_PRIVATE_SLOT(d, void elementAnimationFinished())
Q_PRIVATE_SLOT(d, void setPalette())
FlashingLabelPrivate *const d;
};
}
#endif

View File

@ -1,282 +0,0 @@
/*
* Copyright 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "frame.h"
//Qt
#include <QGraphicsSceneResizeEvent>
#include <QWidget>
#include <QDir>
#include <QPainter>
//KDE
#include <qmimedatabase.h>
//Plasma
#include "framesvg.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
class FramePrivate : public ThemedWidgetInterface<Frame>
{
public:
FramePrivate(Frame *parent)
: ThemedWidgetInterface<Frame>(parent),
svg(0),
image(0),
pixmap(0)
{
}
~FramePrivate()
{
delete pixmap;
}
void syncBorders();
FrameSvg *svg;
Frame::Shadow shadow;
QString text;
QString styleSheet;
QString imagePath;
QString absImagePath;
Svg *image;
QPixmap *pixmap;
};
void FramePrivate::syncBorders()
{
//set margins from the normal element
qreal left, top, right, bottom;
svg->getMargins(left, top, right, bottom);
if (!text.isNull()) {
QFontMetricsF fm(q->font());
top += fm.height();
}
q->setContentsMargins(left, top, right, bottom);
}
Frame::Frame(QGraphicsWidget *parent)
: QGraphicsWidget(parent),
d(new FramePrivate(this))
{
d->svg = new Plasma::FrameSvg(this);
d->svg->setImagePath("widgets/frame");
d->svg->setElementPrefix("plain");
d->syncBorders();
connect(d->svg, SIGNAL(repaintNeeded()), SLOT(syncBorders()));
d->initTheming();
}
Frame::~Frame()
{
delete d;
}
void Frame::setFrameShadow(Shadow shadow)
{
d->shadow = shadow;
switch (d->shadow) {
case Raised:
d->svg->setElementPrefix("raised");
break;
case Sunken:
d->svg->setElementPrefix("sunken");
break;
case Plain:
default:
d->svg->setElementPrefix("plain");
break;
}
d->syncBorders();
}
Frame::Shadow Frame::frameShadow() const
{
return d->shadow;
}
void Frame::setEnabledBorders(const FrameSvg::EnabledBorders borders)
{
if (borders != d->svg->enabledBorders()) {
d->svg->setEnabledBorders(borders);
d->syncBorders();
update();
}
}
FrameSvg::EnabledBorders Frame::enabledBorders() const
{
return d->svg->enabledBorders();
}
void Frame::setText(QString text)
{
d->text = text;
d->syncBorders();
updateGeometry();
update();
}
QString Frame::text() const
{
return d->text;
}
void Frame::setImage(const QString &path)
{
if (d->imagePath == path) {
return;
}
delete d->image;
d->image = 0;
d->imagePath = path;
delete d->pixmap;
d->pixmap = 0;
bool absolutePath = !path.isEmpty() &&
#ifdef Q_OS_WIN
!QDir::isRelativePath(path)
#else
(path[0] == '/' || path.startsWith(QLatin1String(":/")))
#endif
;
if (absolutePath) {
d->absImagePath = path;
} else {
//TODO: package support
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
if (path.isEmpty()) {
return;
}
QMimeDatabase db;
QMimeType mime = db.mimeTypeForFile(d->absImagePath);
if (!mime.inherits("image/svg+xml") && !mime.inherits("application/x-gzip")) {
d->pixmap = new QPixmap(d->absImagePath);
} else {
d->image = new Plasma::Svg(this);
d->image->setImagePath(path);
}
}
QString Frame::image() const
{
return d->imagePath;
}
void Frame::setStyleSheet(const QString &styleSheet)
{
//TODO: implement stylesheets painting
d->styleSheet = styleSheet;
}
QString Frame::styleSheet() const
{
return d->styleSheet;
}
QWidget *Frame::nativeWidget() const
{
return 0;
}
void Frame::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
d->svg->paintFrame(painter);
if (!d->text.isNull()) {
QFontMetricsF fm(font());
QRectF textRect = d->svg->contentsRect();
textRect.setHeight(fm.height());
painter->setFont(font());
painter->setPen(Plasma::Theme::defaultTheme()->color(Theme::TextColor));
painter->drawText(textRect, Qt::AlignHCenter|Qt::AlignTop, d->text);
}
if (!d->imagePath.isNull()) {
if (d->pixmap && !d->pixmap->isNull()) {
painter->drawPixmap(contentsRect(), *d->pixmap, d->pixmap->rect());
} else if (d->image) {
d->image->paint(painter, contentsRect());
}
}
}
void Frame::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->svg->resizeFrame(event->newSize());
if (d->image) {
d->image->resize(contentsRect().size());
}
QGraphicsWidget::resizeEvent(event);
}
QSizeF Frame::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
{
QSizeF hint = QGraphicsWidget::sizeHint(which, constraint);
if (!d->image && !layout()) {
QFontMetricsF fm(font());
qreal left, top, right, bottom;
d->svg->getMargins(left, top, right, bottom);
hint.setHeight(fm.height() + top + bottom);
if (which == Qt::MinimumSize || which == Qt::PreferredSize) {
QRectF rect = fm.boundingRect(d->text);
hint.setWidth(rect.width() + left + right);
}
}
return hint;
}
void Frame::changeEvent(QEvent *event)
{
d->changeEvent(event);
QGraphicsWidget::changeEvent(event);
}
} // namespace Plasma
#include "moc_frame.cpp"

View File

@ -1,152 +0,0 @@
/*
* Copyright 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_FRAME_H
#define PLASMA_FRAME_H
#include <QGraphicsWidget>
#include <plasma/plasma_export.h>
#include <plasma/framesvg.h>
class QFrame;
namespace Plasma
{
class FramePrivate;
/**
* @class Frame plasma/widgets/frame.h <Plasma/Widgets/Frame>
*
* @short A widget that provides a simple frame
*
* A simple frame to group widgets, it can have a plain, sunken or raise aspect
* the default aspect is plain
*/
class PLASMA_EXPORT Frame : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(Shadow frameShadow READ frameShadow WRITE setFrameShadow)
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_ENUMS(Shadow)
public:
enum Shadow {
Plain = 1,
Raised = 2,
Sunken = 3
};
/**
* Constructs a new Frame
*
* @param parent the parent of this widget
*/
explicit Frame(QGraphicsWidget *parent = 0);
~Frame();
/**
* Sets the Frame's shadow style
*
* @param shadow plain, raised or sunken
*/
void setFrameShadow(Shadow shadow);
/**
* @return the Frame's shadow style
*/
Shadow frameShadow() const;
/**
* Sets what borders should be painted
* @param flags borders we want to paint
*/
void setEnabledBorders(const FrameSvg::EnabledBorders borders);
/**
* Convenience method to get the enabled borders
* @return what borders are painted
* @since 4.4
*/
FrameSvg::EnabledBorders enabledBorders() const;
/**
* Set the text to display by this Frame
*
* @param text the text
* @since 4.4
*/
void setText(QString text);
/**
* @return text displayed from this Frame
*/
QString text() const;
/**
* Sets the path to an image to display.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
*/
void setImage(const QString &path);
/**
* @return the image path being displayed currently, or an empty string if none.
*/
QString image() const;
/**
* Sets the stylesheet used to control the visual display of this Frame
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet() const;
/**
* @return the native widget wrapped by this Frame
*/
QWidget *nativeWidget() const;
protected:
void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget = 0);
void resizeEvent(QGraphicsSceneResizeEvent *event);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const;
void changeEvent(QEvent *event);
private:
FramePrivate * const d;
Q_PRIVATE_SLOT(d, void syncBorders())
Q_PRIVATE_SLOT(d, void setPalette())
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,103 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "groupbox.h"
#include <QGroupBox>
#include <QIcon>
#include <QPainter>
#include "svg.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
class GroupBoxPrivate : public ThemedWidgetInterface<GroupBox>
{
public:
GroupBoxPrivate(GroupBox *groupBox)
:ThemedWidgetInterface<GroupBox>(groupBox)
{
}
~GroupBoxPrivate()
{
}
};
GroupBox::GroupBox(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new GroupBoxPrivate(this))
{
QGroupBox *native = new QGroupBox;
d->setWidget(native);
native->setWindowIcon(QIcon());
native->setAttribute(Qt::WA_NoSystemBackground);
d->initTheming();
}
GroupBox::~GroupBox()
{
delete d;
}
void GroupBox::setText(const QString &text)
{
static_cast<QGroupBox*>(widget())->setTitle(text);
}
QString GroupBox::text() const
{
return static_cast<QGroupBox*>(widget())->title();
}
void GroupBox::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString GroupBox::styleSheet()
{
return widget()->styleSheet();
}
QGroupBox *GroupBox::nativeWidget() const
{
return static_cast<QGroupBox*>(widget());
}
void GroupBox::resizeEvent(QGraphicsSceneResizeEvent *event)
{
QGraphicsProxyWidget::resizeEvent(event);
}
void GroupBox::changeEvent(QEvent *event)
{
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include "moc_groupbox.cpp"

View File

@ -1,94 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_GROUPBOX_H
#define PLASMA_GROUPBOX_H
#include <QGraphicsProxyWidget>
class QGroupBox;
#include <plasma/plasma_export.h>
namespace Plasma
{
class GroupBoxPrivate;
/**
* @class GroupBox plasma/widgets/groupbox.h <Plasma/Widgets/GroupBox>
*
* @short Provides a plasma-themed QGroupBox.
*/
class PLASMA_EXPORT GroupBox : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(QGroupBox *nativeWidget READ nativeWidget)
public:
explicit GroupBox(QGraphicsWidget *parent = 0);
~GroupBox();
/**
* Sets the display text for this GroupBox
*
* @param text the text to display; should be translated.
*/
void setText(const QString &text);
/**
* @return the display text
*/
QString text() const;
/**
* Sets the stylesheet used to control the visual display of this GroupBox
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* @return the native widget wrapped by this GroupBox
*/
QGroupBox *nativeWidget() const;
Q_SIGNALS:
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event);
private:
GroupBoxPrivate * const d;
Q_PRIVATE_SLOT(d, void setPalette())
};
} // namespace Plasma
#endif // multiple inclusion guard

File diff suppressed because it is too large Load Diff

View File

@ -1,395 +0,0 @@
/*
* Copyright (C) 2007 by Siraj Razick <siraj@kde.org>
* Copyright (C) 2007 by Riccardo Iaconelli <riccardo@kde.org>
* Copyright (C) 2007 by Matt Broadstone <mbroadst@gmail.com>
* Copyright 2008 by Alexis Ménard <darktears31@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_ICONWIDGET_H
#define PLASMA_ICONWIDGET_H
#include <QtCore/QObject>
#include <QtCore/QWeakPointer>
#include <QGraphicsTextItem>
#include <QIcon>
#include <QGraphicsWidget>
#include <plasma/dataengine.h>
#include <plasma/animator.h>
#include <plasma/plasma_export.h>
class QAction;
class QPropertyAnimation;
/**
* @class IconWidget plasma/widgets/iconwidget.h <Plasma/Widgets/IconWidget>
*
* @short Provides a generic icon.
*
* An icon, in this sense, is not restricted to just an image, but can also
* contain text. Currently, the IconWidget class is primarily used for desktop items,
* but is designed to be used anywhere an icon is needed in an applet.
*
* @author Siraj Razick <siraj@kde.org>
* @author Matt Broadstone <mbroadst@gmail.com>
*/
namespace Plasma
{
class IconWidgetPrivate;
class PLASMA_EXPORT IconWidget : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString infoText READ infoText WRITE setInfoText)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
Q_PROPERTY(QColor textBackgroundColor READ textBackgroundColor WRITE setTextBackgroundColor)
Q_PROPERTY(QSizeF iconSize READ iconSize)
Q_PROPERTY(QString svg READ svg WRITE setSvg)
Q_PROPERTY(bool drawBackground READ drawBackground WRITE setDrawBackground)
Q_PROPERTY(QAction *action READ action WRITE setAction)
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
Q_PROPERTY(int numDisplayLines READ numDisplayLines WRITE setNumDisplayLines)
Q_PROPERTY(QSizeF preferredIconSize READ preferredIconSize WRITE setPreferredIconSize)
Q_PROPERTY(QSizeF minimumIconSize READ minimumIconSize WRITE setMinimumIconSize)
Q_PROPERTY(QSizeF maximumIconSize READ maximumIconSize WRITE setMaximumIconSize)
public:
/**
* Creates a new Plasma::IconWidget.
* @param parent the QGraphicsItem this icon is parented to.
*/
explicit IconWidget(QGraphicsItem *parent = 0);
/**
* Convenience constructor to create a Plasma::IconWidget with text.
* @param text the text that will be displayed with this icon.
* @param parent the QGraphicsItem this icon is parented to.
*/
explicit IconWidget(const QString &text, QGraphicsItem *parent = 0);
/**
* Creates a new Plasma::IconWidget with text and an icon.
* @param icon the icon that will be displayed with this icon.
* @param text the text that will be displayed with this icon.
* @param parent The QGraphicsItem this icon is parented to.
*/
IconWidget(const QIcon &icon, const QString &text, QGraphicsItem *parent = 0);
/**
* Destroys this Plasma::IconWidget.
*/
virtual ~IconWidget();
/**
* Returns the text associated with this icon.
*/
QString text() const;
/**
* Sets the text associated with this icon.
* @param text the text to associate with this icon.
*/
void setText(const QString &text);
/**
* Convenience method to set the svg image to use when given the filepath and name of svg.
* @param svgFilePath the svg filepath including name of the svg.
* @param svgIconElement the svg element to use when displaying the svg. Defaults to all of them.
*/
void setSvg(const QString &svgFilePath, const QString &svgIconElement = QString());
/**
* @return the path to the svg file set, if any
*/
QString svg() const;
/**
* Returns the meta text associated with this icon.
*/
QString infoText() const;
/**
* Sets the additional information to be displayed by
* this icon.
* @param text additional meta text associated with this icon.
*/
void setInfoText(const QString &text);
/**
* @return the icon associated with this icon.
*/
QIcon icon() const;
/**
* Sets the graphical icon for this Plasma::IconWidget.
* @param icon the KDE::icon to associate with this icon.
*/
void setIcon(const QIcon &icon);
/**
* @return the color to use behind the text of the icon
* @since 4.3
*/
QColor textBackgroundColor() const;
/**
* Sets the color to use behind the text of the icon
* @param color the color, or QColor() to reset it to no background color
* @since 4.3
*/
void setTextBackgroundColor(const QColor &color);
/**
* Convenience method to set the icon of this Plasma::IconWidget
* using a QString path to the icon.
* @param icon the path to the icon to associate with this Plasma::IconWidget.
*/
Q_INVOKABLE void setIcon(const QString &icon);
/**
* @return the size of this Plasma::IconWidget's graphical icon.
*/
QSizeF iconSize() const;
/**
* Set the size you prefer the icon will be when positioned in a layout.
* @param preferred icon size, pass an invalid size to unset this value
*
* @since 4.5
*/
void setPreferredIconSize(const QSizeF &size);
/**
* @return The size you prefer the icon will be when positioned in a layout.
* The default is QSizeF(-1, -1); an invalid size means the icon
* will attempt to be at its default and "optimal" size
*
* @since 4.5
*/
QSizeF preferredIconSize() const;
/**
* Set the size that should be the minimum beyond the icon shouldn't scale when
* the icon will be when positioned in a layout.
* @param preferred icon size, pass an invalid size to unset this value
*
* @since 4.5
*/
void setMinimumIconSize(const QSizeF &size);
/**
* @return The size that should be the minimum beyond the icon shouldn't scale when
* the icon will be when positioned in a layout.
* The default is QSizeF(-1, -1); an invalid size means the icon
* will attempt to be at its default and "optimal" size
*
* @since 4.5
*/
QSizeF minimumIconSize() const;
/**
* Set the size that should be the maximum beyond the icon shouldn't scale when
* the icon will be when positioned in a layout.
* @param preferred icon size, pass an invalid size to unset this value
*
* @since 4.5
*/
void setMaximumIconSize(const QSizeF &size);
/**
* @return The size that should be the maximum beyond the icon shouldn't scale when
* the icon will be when positioned in a layout.
* The default is QSizeF(-1, -1); an invalid size means the icon
* will attempt to be at its default and "optimal" size
*
* @since 4.5
*/
QSizeF maximumIconSize() const;
/**
* Plasma::IconWidget allows the user to specify a number of actions
* (currently four) to be displayed around the widget. This method
* allows for a created QAction to be added to the Plasma::IconWidget.
* @param action the QAction to associate with this icon.
*/
void addIconAction(QAction *action);
/**
* Removes a previously set iconAction. The action will be removed from the widget
* but will not be deleted.
*
* @param the QAction to be removed, if 0 all actions will be removed
*/
void removeIconAction(QAction *action);
/**
* Associate an action with this IconWidget
* this makes the IconWidget follow the state of the action, using its icon, text, etc.
* when the IconWidget is clicked, it will also trigger the action.
* Unlike addIconAction, there can be only one associated action.
*/
void setAction(QAction *action);
/**
* @return the currently associated action, if any.
*/
QAction *action() const;
/**
* let set the orientation of the icon
* Qt::Vertical: text under the icon
* Qt::Horizontal text at a side of the icon depending
* by the direction of the language
* @param orientation the orientation we want
*/
void setOrientation(Qt::Orientation orientation);
/**
* @return the orientation of the icon
*/
Qt::Orientation orientation() const;
/**
* inverts the layout of the icons if the orientation is horizontal,
* normally we get icon on the left with left-to-right languages
* @param invert if we want to invert the layout of icons
*/
void invertLayout(bool invert);
/**
* @return if the layout of the icons should appear inverted or not
*/
bool invertedLayout() const;
/**
* @return optimal size given a size for the icon
* @param iconWidth desired width of the icon
*/
Q_INVOKABLE QSizeF sizeFromIconSize(const qreal iconWidth) const;
/**
* @return the number of lines allowed to display
*/
int numDisplayLines();
/**
* @param numLines the number of lines to show in the display.
*/
void setNumDisplayLines(int numLines);
/**
* Sets whether or not to draw a background area for the icon
*
* @param draw true if a background should be drawn or not
*/
void setDrawBackground(bool draw);
/**
* @return true if a background area is to be drawn for the icon
*/
bool drawBackground() const;
/**
* reimplemented from QGraphicsItem
*/
QPainterPath shape() const;
public Q_SLOTS:
/**
* Sets the appearance of the icon to pressed or restores the appearance
* to normal. This does not simulate a mouse button press.
* @param pressed whether to appear as pressed (true) or as normal (false)
*/
void setPressed(bool pressed = true);
/**
* Shortcut for setPressed(false)
*/
void setUnpressed();
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
Q_SIGNALS:
/**
* Indicates when the icon has been pressed.
*/
void pressed(bool down);
/**
* Indicates when the icon has been clicked.
*/
void clicked();
/**
* Indicates when the icon has been double-clicked
*/
void doubleClicked();
/**
* Indicates when the icon has been activated following the single
* or doubleclick settings
*/
void activated();
/**
* Indicates that something about the icon may have changed (image, text, etc)
* only actually works for icons associated with an action
*/
void changed();
protected:
bool isDown();
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
void changeEvent(QEvent *event);
public:
/**
* @internal
**/
void drawActionButtonBase(QPainter *painter, const QSize &size, int element);
private:
Q_PRIVATE_SLOT(d, void syncToAction())
Q_PRIVATE_SLOT(d, void clearAction())
Q_PRIVATE_SLOT(d, void svgChanged())
Q_PRIVATE_SLOT(d, void actionDestroyed(QObject *obj))
Q_PRIVATE_SLOT(d, void hoverAnimationFinished())
Q_PRIVATE_SLOT(d, void colorConfigChanged())
Q_PRIVATE_SLOT(d, void iconConfigChanged())
Q_PRIVATE_SLOT(d, void setPalette())
IconWidgetPrivate * const d;
friend class IconWidgetPrivate;
friend class PopupAppletPrivate;
};
} // namespace Plasma
#endif

View File

@ -1,414 +0,0 @@
/*
* Copyright (C) 2007 by Aaron Seigo <aseigo@kde.org>
* Copyright (C) 2007 by Matt Broadstone <mbroadst@gmail.com>
* Copyright (C) 2006-2007 Fredrik Höglund <fredrik@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_ICONWIDGET_P_H
#define PLASMA_ICONWIDGET_P_H
#include <QtCore/QEvent>
#include <QtCore/QWeakPointer>
#include <QApplication>
#include <QIcon>
#include <QStyleOptionGraphicsItem>
#include <QTextLayout>
#include <QTextOption>
#include "iconwidget.h"
#include "framesvg.h"
#include "private/actionwidgetinterface_p.h"
#include "theme.h"
class QAction;
class QPainter;
class QTextLayout;
class QPropertyAnimation;
namespace Plasma
{
class Animation;
class IconHoverAnimation;
class IconHoverAnimation : public QObject
{
Q_OBJECT
Q_PROPERTY(qreal value READ value WRITE setValue)
public:
IconHoverAnimation(QObject *parent = 0);
qreal value() const;
bool fadeIn() const;
void setFadeIn(bool fadeIn);
QPropertyAnimation *animation() const;
void setAnimation(QPropertyAnimation *animation);
protected slots:
void setValue(qreal value);
private:
qreal m_value;
bool m_fadeIn;
QWeakPointer<QPropertyAnimation> m_animation;
};
class PLASMA_EXPORT IconAction
{
public:
IconAction(IconWidget *icon, QAction *action);
void show();
void hide();
bool isVisible() const;
bool isAnimating() const;
QAction *action() const;
void paint(QPainter *painter) const;
bool event(QEvent::Type type, const QPointF &pos);
void setSelected(bool selected);
bool isSelected() const;
bool isHovered() const;
bool isPressed() const;
void setRect(const QRectF &rect);
QRectF rect() const;
private:
void rebuildPixmap();
IconWidget *m_icon;
QAction *m_action;
QPixmap m_pixmap;
QRectF m_rect;
bool m_hovered;
bool m_pressed;
bool m_selected;
bool m_visible;
QWeakPointer<Animation> m_animation;
};
struct Margin
{
qreal left, right, top, bottom;
};
class IconWidgetPrivate : public ActionWidgetInterface<IconWidget>
{
public:
enum MarginType {
ItemMargin = 0,
TextMargin,
IconMargin,
NMargins
};
enum IconWidgetState {
NoState = 0,
HoverState = 1,
PressedState = 2,
ManualPressedState = 4
};
Q_DECLARE_FLAGS(IconWidgetStates, IconWidgetState)
IconWidgetPrivate(IconWidget *i);
~IconWidgetPrivate();
void changed()
{
emit q->changed();
}
void drawBackground(QPainter *painter, IconWidgetState state);
void drawText(QPainter *painter);
void drawTextItems(QPainter *painter, const QStyleOptionGraphicsItem *option,
const QTextLayout &labelLayout, const QTextLayout &infoLayout) const;
QPixmap decoration(const QStyleOptionGraphicsItem *option, bool useHoverEffect, bool usePressedEffect);
QPointF iconPosition(const QStyleOptionGraphicsItem *option, const QPixmap &pixmap) const;
QSizeF displaySizeHint(const QStyleOptionGraphicsItem *option, const qreal width) const;
QBrush foregroundBrush(const QStyleOptionGraphicsItem *option) const;
QBrush backgroundBrush(const QStyleOptionGraphicsItem *option) const;
QString elidedText(QTextLayout &layout,
const QSizeF &maxSize) const;
QSizeF layoutText(QTextLayout &layout,
const QString &text, const QSizeF &constraints) const;
QSizeF layoutText(QTextLayout &layout, const QString &text,
qreal maxWidth) const;
QRectF labelRectangle(const QStyleOptionGraphicsItem *option,
const QPixmap &icon, const QString &string) const;
void layoutTextItems(const QStyleOptionGraphicsItem *option,
const QPixmap &icon, QTextLayout *labelLayout,
QTextLayout *infoLayout, QRectF *textBoundingRect) const;
int maxWordWidth(const QString text) const;
inline void setLayoutOptions(QTextLayout &layout,
const QStyleOptionGraphicsItem *options,
const Qt::Orientation orientation) const;
inline Qt::LayoutDirection iconDirection(const QStyleOptionGraphicsItem *option) const;
enum {
Minibutton = 64,
MinibuttonHover = 128,
MinibuttonPressed = 256
};
enum ActionPosition {
TopLeft = 0,
TopRight,
BottomLeft,
BottomRight,
LastIconPosition = BottomRight
};
// Margin functions
inline void setActiveMargins();
void setVerticalMargin(MarginType type, qreal left, qreal right, qreal top, qreal bottom);
void setHorizontalMargin(MarginType type, qreal left, qreal right, qreal top, qreal bottom);
inline void setVerticalMargin(MarginType type, qreal hor, qreal ver);
inline void setHorizontalMargin(MarginType type, qreal hor, qreal ver);
inline QRectF addMargin(const QRectF &rect, MarginType type) const;
inline QRectF subtractMargin(const QRectF &rect, MarginType type) const;
inline QSizeF addMargin(const QSizeF &size, MarginType type) const;
inline QSizeF subtractMargin(const QSizeF &size, MarginType type) const;
inline QRectF actionRect(ActionPosition position) const;
void actionDestroyed(QObject *obj);
void svgChanged();
void readColors();
void colorConfigChanged();
void iconConfigChanged();
void hoverAnimationFinished();
void init();
void layoutIcons(const QStyleOptionGraphicsItem *option);
QSizeF iconSizeForWidgetSize(const QStyleOptionGraphicsItem *option, const QSizeF &widgetSize);
void animateMainIcon(bool, const IconWidgetStates state);
QString text;
QString infoText;
Svg *iconSvg;
FrameSvg *background;
QString iconSvgElement;
QPixmap iconSvgPixmap;
QColor textColor;
QColor textBgColor;
QColor shadowColor;
IconHoverAnimation *hoverAnimation;
QSizeF iconSize;
QSizeF preferredIconSize;
QSizeF minimumIconSize;
QSizeF maximumIconSize;
QIcon icon;
QIcon oldIcon;
IconWidgetStates states;
Qt::Orientation orientation;
int numDisplayLines;
QSizeF currentSize;
QPointF clickStartPos;
mutable QList<QRect> haloRects;
QTimer *iconChangeTimer;
QList<IconAction*> cornerActions;
Margin verticalMargin[NMargins];
Margin horizontalMargin[NMargins];
Margin *activeMargins;
bool iconSvgElementChanged : 1;
bool invertLayout : 1;
bool drawBg : 1;
bool textBgCustomized : 1;
static const int maxDisplayLines = 5;
static const int iconActionSize = 26;
static const int iconActionMargin = 4;
bool customFont;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(IconWidgetPrivate::IconWidgetStates)
// Inline methods
void IconWidgetPrivate::setLayoutOptions(QTextLayout &layout,
const QStyleOptionGraphicsItem *option,
const Qt::Orientation orientation) const
{
QTextOption textoption;
textoption.setTextDirection(option->direction);
if (orientation == Qt::Horizontal) {
textoption.setAlignment(Qt::Alignment(Qt::AlignLeft|Qt::AlignVCenter));
} else {
textoption.setAlignment(Qt::AlignCenter);
}
textoption.setWrapMode(QTextOption::WordWrap); // NOTE: assumption as well
layout.setFont(q->font());
layout.setTextOption(textoption);
}
Qt::LayoutDirection IconWidgetPrivate::iconDirection(const QStyleOptionGraphicsItem *option) const
{
Qt::LayoutDirection direction;
if (invertLayout && orientation == Qt::Horizontal) {
if (option->direction == Qt::LeftToRight) {
direction = Qt::RightToLeft;
} else {
direction = Qt::LeftToRight;
}
} else {
direction = option->direction;
}
return direction;
}
void IconWidgetPrivate::setActiveMargins()
{
//sync here itemmargin with contentsrect, not overly pretty but it's where it's more reliable
qreal left, top, right, bottom;
q->getContentsMargins(&left, &top, &right, &bottom);
if (left || top || right || bottom) {
verticalMargin[ItemMargin].left = horizontalMargin[ItemMargin].left = left;
verticalMargin[ItemMargin].top = horizontalMargin[ItemMargin].top = top;
verticalMargin[ItemMargin].right = horizontalMargin[ItemMargin].right = right;
verticalMargin[ItemMargin].bottom = horizontalMargin[ItemMargin].bottom = bottom;
}
activeMargins = (orientation == Qt::Horizontal ? horizontalMargin : verticalMargin);
}
void IconWidgetPrivate::setVerticalMargin(MarginType type, qreal left, qreal top,
qreal right, qreal bottom)
{
verticalMargin[type].left = left;
verticalMargin[type].right = right;
verticalMargin[type].top = top;
verticalMargin[type].bottom = bottom;
}
void IconWidgetPrivate::setHorizontalMargin(MarginType type, qreal left, qreal top,
qreal right, qreal bottom)
{
horizontalMargin[type].left = left;
horizontalMargin[type].right = right;
horizontalMargin[type].top = top;
horizontalMargin[type].bottom = bottom;
}
void IconWidgetPrivate::setVerticalMargin(MarginType type, qreal horizontal, qreal vertical)
{
setVerticalMargin(type, horizontal, vertical, horizontal, vertical);
}
void IconWidgetPrivate::setHorizontalMargin(MarginType type, qreal horizontal, qreal vertical)
{
setHorizontalMargin(type, horizontal, vertical, horizontal, vertical);
}
QRectF IconWidgetPrivate::addMargin(const QRectF &rect, MarginType type) const
{
Q_ASSERT(activeMargins);
const Margin &m = activeMargins[type];
return rect.adjusted(-m.left, -m.top, m.right, m.bottom);
}
QRectF IconWidgetPrivate::subtractMargin(const QRectF &rect, MarginType type) const
{
Q_ASSERT(activeMargins);
const Margin &m = activeMargins[type];
return rect.adjusted(m.left, m.top, -m.right, -m.bottom);
}
QSizeF IconWidgetPrivate::addMargin(const QSizeF &size, MarginType type) const
{
Q_ASSERT(activeMargins);
const Margin &m = activeMargins[type];
return QSizeF(size.width() + m.left + m.right, size.height() + m.top + m.bottom);
}
QSizeF IconWidgetPrivate::subtractMargin(const QSizeF &size, MarginType type) const
{
Q_ASSERT(activeMargins);
const Margin &m = activeMargins[type];
return QSizeF(size.width() - m.left - m.right, size.height() - m.top - m.bottom);
}
int IconWidgetPrivate::maxWordWidth(const QString text) const
{
QFontMetricsF fm = Plasma::Theme::defaultTheme()->fontMetrics();
QStringList words = text.split(' ');
qreal maxWidth = 0;
foreach (const QString &word, words) {
maxWidth = qMax(maxWidth, fm.width(word));
}
return maxWidth;
}
QRectF IconWidgetPrivate::actionRect(ActionPosition position) const
{
switch (position) {
case TopLeft:
return QRectF(iconActionMargin,
iconActionMargin,
iconActionSize,
iconActionSize);
case TopRight:
return QRectF(currentSize.width() - iconActionSize - iconActionMargin,
iconActionMargin,
iconActionSize,
iconActionSize);
case BottomLeft:
return QRectF(iconActionMargin,
currentSize.height() - iconActionSize - iconActionMargin,
iconActionSize,
iconActionSize);
//BottomRight
default:
return QRectF(currentSize.width() - iconActionSize - iconActionMargin,
currentSize.height() - iconActionSize - iconActionMargin,
iconActionSize,
iconActionSize);
}
}
} // Namespace
#endif

View File

@ -1,347 +0,0 @@
/***************************************************************************
* Copyright 2009 by Alessandro Diaferia <alediaferia@gmail.com> *
* Copyright 2009 by Marco Martin <notmart@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "itembackground.h"
#include <QPainter>
#include <QTimer>
#include <QStyleOptionGraphicsItem>
#include <QPropertyAnimation>
#include <kdebug.h>
#include <plasma/framesvg.h>
#include <plasma/animator.h>
#include <plasma/theme.h>
namespace Plasma
{
class ItemBackgroundPrivate
{
public:
ItemBackgroundPrivate(ItemBackground *parent)
: q(parent),
target(0)
{}
void animationUpdate(qreal progress);
void targetDestroyed(QObject*);
void frameSvgChanged();
void refreshCurrentTarget();
ItemBackground * const q;
QGraphicsItem *target;
Plasma::FrameSvg *frameSvg;
QRectF oldGeometry;
QRectF newGeometry;
QPropertyAnimation *anim;
qreal opacity;
bool fading;
bool fadeIn;
bool immediate;
};
ItemBackground::ItemBackground(QGraphicsWidget *parent)
: QGraphicsWidget(parent),
d(new ItemBackgroundPrivate(this))
{
d->frameSvg = new Plasma::FrameSvg(this);
d->anim = new QPropertyAnimation(this, "animationUpdate", this);
d->anim->setStartValue(0);
d->anim->setEndValue(1);
d->opacity = 1;
d->fading = false;
d->fadeIn = false;
d->immediate = false;
d->frameSvg->setImagePath("widgets/viewitem");
d->frameSvg->setEnabledBorders(Plasma::FrameSvg::AllBorders);
d->frameSvg->setCacheAllRenderedFrames(true);
d->frameSvg->setElementPrefix("hover");
setCacheMode(DeviceCoordinateCache);
setFlag(ItemIsMovable, false);
setFlag(ItemIsSelectable, false);
setFlag(ItemIsFocusable, false);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
qreal l, t, r, b;
d->frameSvg->getMargins(l, t, r, b);
setContentsMargins(l, t, r, b);
connect(d->frameSvg, SIGNAL(repaintNeeded()), this, SLOT(frameSvgChanged()));
setAcceptedMouseButtons(0);
setZValue(-800);
}
ItemBackground::~ItemBackground()
{
delete d;
}
QRectF ItemBackground::target() const
{
return d->newGeometry;
}
void ItemBackground::setTarget(const QRectF &newGeometry)
{
d->oldGeometry = geometry();
d->newGeometry = newGeometry;
if (!isVisible() && (!d->target || !d->target->isVisible())) {
setGeometry(d->newGeometry);
targetReached(newGeometry);
if (d->target) {
emit targetItemReached(d->target);
}
return;
}
QGraphicsWidget *pw = parentWidget();
if (pw) {
d->newGeometry = d->newGeometry.intersected(QRectF(QPointF(0,0), pw->size()));
}
if (d->anim->state() != QAbstractAnimation::Stopped) {
d->anim->stop();
}
if (d->target && d->target->isVisible() && !isVisible()) {
setZValue(d->target->zValue()-1);
setGeometry(newGeometry);
d->oldGeometry = newGeometry;
show();
} else {
d->fading = false;
d->opacity = 1;
d->anim->start();
}
}
void ItemBackground::setTargetItem(QGraphicsItem *target)
{
if (d->target && d->target != target) {
QObject *obj = 0;
if (d->target->isWidget()) {
obj = static_cast<QGraphicsWidget*>(d->target);
obj->removeEventFilter(this);
} else {
d->target->removeSceneEventFilter(this);
obj = dynamic_cast<QObject *>(d->target);
}
if (obj) {
disconnect(obj, 0, this, 0);
}
}
if (!target) {
hide();
}
bool newTarget = (d->target != target);
d->target = target;
if (target) {
setZValue(target->zValue() - 1);
if (parentItem() != target->parentItem()) {
QTransform t = transform();
setTransform(QTransform());
QRectF geom = mapToScene(geometry()).boundingRect();
setGeometry(mapFromScene(geom).boundingRect());
setTransform(t);
}
QRectF rect = target->boundingRect();
rect.moveTopLeft(mapToParent(mapFromScene(target->mapToScene(QPointF(0, 0)))));
setTarget(rect);
if (newTarget) {
QObject *obj = 0;
if (target->isWidget()) {
obj = static_cast<QGraphicsWidget*>(target);
obj->installEventFilter(this);
} else {
d->target->installSceneEventFilter(this);
obj = dynamic_cast<QObject *>(target);
}
if (obj) {
connect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(targetDestroyed(QObject*)));
}
}
}
}
QGraphicsItem *ItemBackground::targetItem() const
{
return d->target;
}
bool ItemBackground::eventFilter(QObject *watched, QEvent *event)
{
QGraphicsWidget *targetWidget = static_cast<QGraphicsWidget *>(d->target);
if (watched == targetWidget) {
if (event->type() == QEvent::GraphicsSceneResize ||
event->type() == QEvent::GraphicsSceneMove) {
// We need to wait for the parent widget to resize...
QTimer::singleShot(0, this, SLOT(refreshCurrentTarget()) );
} else if (event->type() == QEvent::Show) {
setTargetItem(targetWidget);
}
}
return false;
}
bool ItemBackground::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
{
if (watched == d->target) {
if (event->type() == QEvent::GraphicsSceneMove) {
QTimer::singleShot(0, this, SLOT(refreshCurrentTarget()) );
}
}
return false;
}
void ItemBackground::resizeEvent(QGraphicsSceneResizeEvent *)
{
d->frameSvg->resizeFrame(size());
}
QVariant ItemBackground::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (d->immediate) {
return value;
}
if (change == ItemVisibleChange) {
bool visible = value.toBool();
bool retVisible = visible;
if (visible == isVisible() || d->anim->state() == QAbstractAnimation::Stopped) {
retVisible = true;
}
d->fading = true;
d->fadeIn = visible;
if (d->anim->state() != QAbstractAnimation::Stopped) {
d->anim->stop();
}
d->anim->setDuration(100);
d->anim->start();
return retVisible;
}
return value;
}
void ItemBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget)
if (qFuzzyCompare(d->opacity, (qreal)1.0)) {
d->frameSvg->paintFrame(painter, option->rect.topLeft());
} else if (qFuzzyCompare(d->opacity+1, (qreal)1.0)) {
return;
} else {
QPixmap framePix = d->frameSvg->framePixmap();
QPainter bufferPainter(&framePix);
bufferPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
bufferPainter.fillRect(framePix.rect(), QColor(0, 0, 0, 255 * d->opacity));
bufferPainter.end();
painter->drawPixmap(framePix.rect(), framePix, framePix.rect());
}
}
void ItemBackground::setAnimationUpdate(qreal progress)
{
d->animationUpdate(progress);
}
qreal ItemBackground::animationUpdate() const
{
return d->opacity;
}
void ItemBackgroundPrivate::animationUpdate(qreal progress)
{
if (progress == 1) {
if ((!fading) || (fadeIn)) {
emit q->targetReached(newGeometry);
if (target) {
emit q->targetItemReached(target);
}
}
}
if (fading) {
opacity = fadeIn?progress:1-progress;
if (!fadeIn && qFuzzyCompare(opacity+1, (qreal)1.0)) {
immediate = true;
q->hide();
immediate = false;
}
} else if (oldGeometry != newGeometry) {
q->setGeometry(oldGeometry.x() + (newGeometry.x() - oldGeometry.x()) * progress,
oldGeometry.y() + (newGeometry.y() - oldGeometry.y()) * progress,
oldGeometry.width() + (newGeometry.width() - oldGeometry.width()) * progress,
oldGeometry.height() + (newGeometry.height() - oldGeometry.height()) * progress);
}
q->update();
emit q->animationStep(progress);
}
void ItemBackgroundPrivate::targetDestroyed(QObject*)
{
target = 0;
q->setTargetItem(0);
}
void ItemBackgroundPrivate::frameSvgChanged()
{
qreal l, t, r, b;
frameSvg->getMargins(l, t, r, b);
q->setContentsMargins(l, t, r, b);
q->update();
emit q->appearanceChanged();
}
void ItemBackgroundPrivate::refreshCurrentTarget()
{
q->setTargetItem(target);
}
} // Plasma namespace
#include "moc_itembackground.cpp"

View File

@ -1,138 +0,0 @@
/***************************************************************************
* Copyright 2009 by Alessandro Diaferia <alediaferia@gmail.com> *
* Copyright 2009 by Marco Martin <notmart@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#ifndef ITEMBACKGROUND_H
#define ITEMBACKGROUND_H
#include <QGraphicsWidget>
#include <plasma/plasma_export.h>
/**
* @class ItemBackground plasma/widgets/itembackground.h
*
* @short a background for QGraphicsWidget based item views with animation effects
*
* @since 4.4
*/
namespace Plasma {
class FrameSvg;
class ItemBackgroundPrivate;
class PLASMA_EXPORT ItemBackground : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(QRectF target READ target WRITE setTarget)
Q_PROPERTY(QGraphicsItem* targetItem READ targetItem WRITE setTargetItem)
Q_PROPERTY(qreal animationUpdate READ animationUpdate WRITE setAnimationUpdate)
public:
ItemBackground(QGraphicsWidget *parent = 0);
~ItemBackground();
/**
* Sets a new target geometry we want at the end of animation
*
* @param newGeometry the final geometry target
*/
void setTarget(const QRectF &newGeometry);
/**
* @return the current target rect; may be empty if there is no target currently set
*/
QRectF target() const;
/**
* set the ItemBackground geometry to be the target geometry, plus the ItemBackground margins
*/
void setTargetItem(QGraphicsItem *target);
/**
* @return the target item, if any
*/
QGraphicsItem *targetItem() const;
/**
* @reimp from QGraphicsWidget
*/
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
Q_SIGNALS:
/**
* Emitted when the visual layout and appearance changes. Useful for synchronizing
* content margins.
*/
void appearanceChanged();
/**
* Emitted at each animation frame. Useful for synchronizing item animations
*/
void animationStep(qreal progress);
/**
* Emitted when the target has been reached. Useful to consider this instead of
* the corresponding hoverEnterEvent;
*/
void targetReached(QRectF);
/**
* Emitted when the target has been reached. Useful to consider this instead of
* the corresponding hoverEnterEvent;
*/
void targetItemReached(QGraphicsItem *);
protected:
/**
* @reimp from QGraphicsWidget
*/
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
/**
* @reimp from QObject
*/
bool eventFilter(QObject *watched, QEvent *event);
/**
* @reimp from QGraphicsItem
*/
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
/**
* @reimp from QGraphicsItem
*/
void resizeEvent(QGraphicsSceneResizeEvent *);
private:
void setAnimationUpdate(qreal progress);
qreal animationUpdate() const;
private:
Q_PRIVATE_SLOT(d, void targetDestroyed(QObject*))
Q_PRIVATE_SLOT(d, void frameSvgChanged())
Q_PRIVATE_SLOT(d, void refreshCurrentTarget())
friend class ItemBackgroundPrivate;
ItemBackgroundPrivate * const d;
};
}
#endif

View File

@ -1,354 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "label.h"
#include <QApplication>
#include <QDir>
#include <QGraphicsSceneMouseEvent>
#include <QLabel>
#include <QMenu>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <kcolorscheme.h>
#include <kglobalsettings.h>
#include <qmimedatabase.h>
#include "private/themedwidgetinterface_p.h"
#include "svg.h"
#include "theme.h"
namespace Plasma
{
class LabelPrivate : public ThemedWidgetInterface<Label>
{
public:
LabelPrivate(Label *label)
: ThemedWidgetInterface<Label>(label),
svg(0),
textSelectable(false),
hasLinks(false)
{
}
~LabelPrivate()
{
delete svg;
}
void setPixmap()
{
if (imagePath.isEmpty()) {
delete svg;
svg = 0;
return;
}
QMimeDatabase db;
QMimeType mime = db.mimeTypeForFile(absImagePath);
QPixmap pm(q->size().toSize());
if (mime.inherits("image/svg+xml") || mime.inherits("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != absImagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
}
QPainter p(&pm);
svg->paint(&p, pm.rect());
} else {
delete svg;
svg = 0;
pm = QPixmap(absImagePath);
}
static_cast<QLabel*>(q->widget())->setPixmap(pm);
}
QString imagePath;
QString absImagePath;
Svg *svg;
bool textSelectable : 1;
bool hasLinks : 1;
};
Label::Label(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new LabelPrivate(this))
{
QLabel *native = new QLabel;
native->setWindowFlags(native->windowFlags()|Qt::BypassGraphicsProxyWidget);
native->setAttribute(Qt::WA_NoSystemBackground);
native->setWordWrap(true);
native->setWindowIcon(QIcon());
connect(native, SIGNAL(linkActivated(QString)), this, SIGNAL(linkActivated(QString)));
connect(native, SIGNAL(linkHovered(QString)), this, SIGNAL(linkHovered(QString)));
d->setWidget(native);
d->initTheming();
}
Label::~Label()
{
delete d;
}
void Label::setText(const QString &text)
{
d->hasLinks = text.contains("<a ", Qt::CaseInsensitive);
static_cast<QLabel*>(widget())->setText(text);
updateGeometry();
}
QString Label::text() const
{
return static_cast<QLabel*>(widget())->text();
}
void Label::setImage(const QString &path)
{
if (d->imagePath == path) {
return;
}
delete d->svg;
d->svg = 0;
d->imagePath = path;
bool absolutePath = !path.isEmpty() &&
#ifdef Q_OS_WIN
!QDir::isRelativePath(path)
#else
(path[0] == '/' || path.startsWith(QLatin1String(":/")))
#endif
;
if (absolutePath) {
d->absImagePath = path;
} else {
//TODO: package support
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap();
}
QString Label::image() const
{
return d->imagePath;
}
void Label::setScaledContents(bool scaled)
{
static_cast<QLabel*>(widget())->setScaledContents(scaled);
}
bool Label::hasScaledContents() const
{
return static_cast<QLabel*>(widget())->hasScaledContents();
}
void Label::setTextSelectable(bool enable)
{
if (enable) {
nativeWidget()->setTextInteractionFlags(Qt::TextBrowserInteraction);
} else {
nativeWidget()->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
}
d->textSelectable = enable;
}
bool Label::textSelectable() const
{
return d->textSelectable;
}
void Label::setAlignment(Qt::Alignment alignment)
{
nativeWidget()->setAlignment(alignment);
}
Qt::Alignment Label::alignment() const
{
return nativeWidget()->alignment();
}
void Label::setWordWrap(bool wrap)
{
nativeWidget()->setWordWrap(wrap);
}
bool Label::wordWrap() const
{
return nativeWidget()->wordWrap();
}
void Label::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString Label::styleSheet()
{
return widget()->styleSheet();
}
QLabel *Label::nativeWidget() const
{
return static_cast<QLabel*>(widget());
}
void Label::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
{
Q_UNUSED(sourceName);
QStringList texts;
foreach (const QVariant &v, data) {
if (v.canConvert(QVariant::String)) {
texts << v.toString();
}
}
setText(texts.join(" "));
}
void Label::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
if (d->textSelectable || d->hasLinks){
QContextMenuEvent contextMenuEvent(QContextMenuEvent::Reason(event->reason()),
event->pos().toPoint(), event->screenPos(), event->modifiers());
QApplication::sendEvent(nativeWidget(), &contextMenuEvent);
}else{
event->ignore();
}
}
void Label::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap();
QGraphicsProxyWidget::resizeEvent(event);
}
void Label::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsProxyWidget::mousePressEvent(event);
//FIXME: when QTextControl accept()s mouse press events (as of Qt 4.6.2, it processes them
//but never marks them as accepted) the following event->accept() can be removed
if (d->textSelectable || d->hasLinks) {
event->accept();
}
}
void Label::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (d->textSelectable) {
QGraphicsProxyWidget::mouseMoveEvent(event);
}
}
void Label::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
QLabel *native = nativeWidget();
QFontMetrics fm(native->font());
//indirect painting still used for fade out
if (native->wordWrap() || native->text().isEmpty() || size().width() >= fm.width(native->text())) {
QGraphicsProxyWidget::paint(painter, option, widget);
} else {
const int gradientLength = 25;
QPixmap buffer(contentsRect().size().toSize());
buffer.fill(Qt::transparent);
QPainter buffPainter(&buffer);
QGraphicsProxyWidget::paint(&buffPainter, option, widget);
QLinearGradient gr;
buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
buffPainter.setPen(Qt::NoPen);
if (option->direction == Qt::LeftToRight) {
gr.setStart(size().width()-gradientLength, 0);
gr.setFinalStop(size().width(), 0);
gr.setColorAt(0, Qt::black);
gr.setColorAt(1, Qt::transparent);
buffPainter.setBrush(gr);
buffPainter.drawRect(QRect(gr.start().toPoint(), QSize(gradientLength, size().height())));
} else {
gr.setStart(0, 0);
gr.setFinalStop(gradientLength, 0);
gr.setColorAt(0, Qt::transparent);
gr.setColorAt(1, Qt::black);
buffPainter.setBrush(gr);
buffPainter.drawRect(QRect(0, 0, gradientLength, size().height()));
}
buffPainter.end();
painter->drawPixmap(contentsRect(), buffer, buffer.rect());
}
}
void Label::changeEvent(QEvent *event)
{
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}
bool Label::event(QEvent *event)
{
d->event(event);
return QGraphicsProxyWidget::event(event);
}
QVariant Label::itemChange(GraphicsItemChange change, const QVariant & value)
{
if (change == QGraphicsItem::ItemCursorHasChanged) {
nativeWidget()->setCursor(cursor());
}
return QGraphicsWidget::itemChange(change, value);
}
QSizeF Label::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
if (sizePolicy().verticalPolicy() == QSizePolicy::Fixed) {
return QGraphicsProxyWidget::sizeHint(Qt::PreferredSize, constraint);
} else {
return QGraphicsProxyWidget::sizeHint(which, constraint);
}
}
} // namespace Plasma
#include "moc_label.cpp"

View File

@ -1,185 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_LABEL_H
#define PLASMA_LABEL_H
#include <QGraphicsProxyWidget>
#include <plasma/plasma_export.h>
#include <plasma/dataengine.h>
class QLabel;
namespace Plasma
{
class LabelPrivate;
/**
* @class Label plasma/widgets/label.h <Plasma/Widgets/Label>
*
* @short Provides a plasma-themed QLabel.
*/
class PLASMA_EXPORT Label : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
Q_PROPERTY(bool hasScaledContents READ hasScaledContents WRITE setScaledContents)
Q_PROPERTY(bool textSelectable READ textSelectable WRITE setTextSelectable)
Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(QLabel *nativeWidget READ nativeWidget)
public:
/**
* Constructs a label with word wrap on by default
*
* @param parent the parent of this widget
*/
explicit Label(QGraphicsWidget *parent = 0);
~Label();
/**
* Sets the display text for this Label
*
* @param text the text to display; should be translated.
*/
void setText(const QString &text);
/**
* @return the display text
*/
QString text() const;
/**
* Sets the path to an image to display.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
*/
void setImage(const QString &path);
/**
* @return the image path being displayed currently, or an empty string if none.
*/
QString image() const;
/**
* Sets the alignment for the text
*
* @param the desired alignment
*/
void setAlignment(Qt::Alignment alignment);
/**
* @return the alignment for the text used in the labels
*/
Qt::Alignment alignment() const;
/**
* Scale or not the contents of the label to the label size
*
* @param scale
*/
void setScaledContents(bool scaled);
/**
* @return true if the contents are scaled to the label size
*/
bool hasScaledContents() const;
/**
* Set if the text on the label can be selected with the mouse
*
* @param enable true if we want to manage text selection with the mouse
* @since 4.4
*/
void setTextSelectable(bool enable);
/**
* @return true if the text is selectable with the mouse
* @since 4.4
*/
bool textSelectable() const;
/**
* Sets if the text of the label can wrap in multiple lines
*
* @param wrap multiple lines or not
* @since 4.5
*/
void setWordWrap(bool wrap);
/**
* @return true if the label text can wrap in multiple lines if too long
* @since 4.5
*/
bool wordWrap() const;
/**
* Sets the stylesheet used to control the visual display of this Label
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* @return the native widget wrapped by this Label
*/
QLabel *nativeWidget() const;
Q_SIGNALS:
void linkActivated(const QString &link);
void linkHovered(const QString &link);
public Q_SLOTS:
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget);
void changeEvent(QEvent *event);
bool event(QEvent *event);
QVariant itemChange(GraphicsItemChange change, const QVariant & value);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
private:
Q_PRIVATE_SLOT(d, void setPalette())
Q_PRIVATE_SLOT(d, void setPixmap())
LabelPrivate * const d;
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,247 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "lineedit.h"
#include <QGraphicsSceneResizeEvent>
#include <QIcon>
#include <QPainter>
#include <QGraphicsView>
#include <klineedit.h>
#include "applet.h"
#include "framesvg.h"
#include "graphicsview/private/style_p.h"
#include "graphicsview/private/focusindicator_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
class LineEditPrivate : public ThemedWidgetInterface<LineEdit>
{
public:
LineEditPrivate(LineEdit *lineEdit)
: ThemedWidgetInterface<LineEdit>(lineEdit)
{
buttonColorForText = true;
}
~LineEditPrivate()
{
}
LineEdit *q;
Plasma::Style::Ptr style;
Plasma::FrameSvg *background;
};
LineEdit::LineEdit(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new LineEditPrivate(this))
{
d->style = Plasma::Style::sharedStyle();
d->background = new Plasma::FrameSvg(this);
d->background->setImagePath("widgets/lineedit");
d->background->setCacheAllRenderedFrames(true);
#if 0 // causes bug 290111
FocusIndicator *indicator = new FocusIndicator(this, d->background);
if (d->background->hasElement("hint-focus-over-base")) {
indicator->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
}
#endif
setNativeWidget(new KLineEdit);
}
LineEdit::~LineEdit()
{
delete d;
Plasma::Style::doneWithSharedStyle();
}
void LineEdit::setText(const QString &text)
{
static_cast<KLineEdit*>(widget())->setText(text);
}
QString LineEdit::text() const
{
return static_cast<KLineEdit*>(widget())->text();
}
void LineEdit::setClearButtonShown(bool show)
{
nativeWidget()->setClearButtonShown(show);
}
bool LineEdit::isClearButtonShown() const
{
return nativeWidget()->isClearButtonShown();
}
#ifndef KDE_NO_DEPRECATED
void LineEdit::setClickMessage(const QString &message)
{
setPlaceholderText(message);
}
#endif
void LineEdit::setPlaceholderText(const QString &message)
{
nativeWidget()->setPlaceholderText(message);
}
#ifndef KDE_NO_DEPRECATED
QString LineEdit::clickMessage() const
{
return placeholderText();
}
#endif
QString LineEdit::placeholderText() const
{
return nativeWidget()->placeholderText();
}
void LineEdit::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString LineEdit::styleSheet()
{
return widget()->styleSheet();
}
void LineEdit::setNativeWidget(KLineEdit *nativeWidget)
{
if (widget()) {
widget()->deleteLater();
}
connect(nativeWidget, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
connect(nativeWidget, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
connect(nativeWidget, SIGNAL(textEdited(QString)), this, SIGNAL(textEdited(QString)));
connect(nativeWidget, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged(QString)));
nativeWidget->setWindowFlags(nativeWidget->windowFlags()|Qt::BypassGraphicsProxyWidget);
d->setWidget(nativeWidget);
nativeWidget->setWindowIcon(QIcon());
nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
nativeWidget->setStyle(d->style.data());
d->initTheming();
}
KLineEdit *LineEdit::nativeWidget() const
{
return static_cast<KLineEdit*>(widget());
}
void LineEdit::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
update();
}
void LineEdit::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
update();
}
void LineEdit::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
nativeWidget()->render(painter, QPoint(0, 0), QRegion(), QWidget::DrawChildren|QWidget::IgnoreMask);
}
void LineEdit::changeEvent(QEvent *event)
{
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}
void LineEdit::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsWidget *widget = parentWidget();
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
while (!applet && widget) {
widget = widget->parentWidget();
applet = qobject_cast<Plasma::Applet *>(widget);
}
if (applet) {
applet->setStatus(Plasma::AcceptingInputStatus);
}
QGraphicsProxyWidget::mousePressEvent(event);
}
void LineEdit::focusInEvent(QFocusEvent *event)
{
QGraphicsProxyWidget::focusInEvent(event);
if (!nativeWidget()->hasFocus()) {
// as of Qt 4.7, apparently we have a bug here in QGraphicsProxyWidget
nativeWidget()->setFocus(event->reason());
}
emit focusChanged(true);
}
void LineEdit::focusOutEvent(QFocusEvent *event)
{
QGraphicsWidget *widget = parentWidget();
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
while (!applet && widget) {
widget = widget->parentWidget();
applet = qobject_cast<Plasma::Applet *>(widget);
}
if (applet) {
applet->setStatus(Plasma::UnknownStatus);
}
QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
if (qApp) {
if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
if (view->scene() && view->scene() == scene()) {
QApplication::sendEvent(view, &closeEvent);
}
}
}
QGraphicsProxyWidget::focusOutEvent(event);
emit focusChanged(false);
}
} // namespace Plasma
#include "moc_lineedit.cpp"

View File

@ -1,173 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_LINEEDIT_H
#define PLASMA_LINEEDIT_H
#include <QGraphicsProxyWidget>
class KLineEdit;
#include <plasma/plasma_export.h>
namespace Plasma
{
class LineEditPrivate;
/**
* @class LineEdit plasma/widgets/lineedit.h <Plasma/Widgets/LineEdit>
*
* @short Provides a plasma-themed KLineEdit.
*/
class PLASMA_EXPORT LineEdit : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(bool clearButtonShown READ isClearButtonShown WRITE setClearButtonShown)
#ifndef KDE_NO_DEPRECATED
Q_PROPERTY(QString clickMessage READ clickMessage WRITE setClickMessage)
#endif
Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(KLineEdit *nativeWidget READ nativeWidget WRITE setNativeWidget)
public:
explicit LineEdit(QGraphicsWidget *parent = 0);
~LineEdit();
/**
* Sets the display text for this LineEdit
*
* @param text the text to display; should be translated.
*/
void setText(const QString &text);
/**
* @return the display text
*/
QString text() const;
/**
* Shows a button to clear the text
* @since 4.3
*/
void setClearButtonShown(bool show);
/**
* @return true if the clear button is set to be shown
* @since 4.3
*/
bool isClearButtonShown() const;
/**
* Sets a grayed out message that will go away after the user clicked the line edit
*
* @param message the message
* @since 4.5
* @deprecated use LineEdit::setPlaceholderText instead
*/
#ifndef KDE_NO_DEPRECATED
PLASMA_DEPRECATED void setClickMessage(const QString &message);
#endif
/**
* @return the text of a grayed out message that will go away when clicked
* @since 4.5
* @deprecated use LineEdit::placeholderText instead
*/
#ifndef KDE_NO_DEPRECATED
PLASMA_DEPRECATED QString clickMessage() const;
#endif
/**
* @return the message set with setPlaceholderText
* @since 5.0
*/
QString placeholderText() const;
/**
* This makes the KUrlRequester line edit display a grayed-out hinting text as long as
* the user didn't enter any text. It is often used as indication about
* the purpose of the line edit.
* @since 5.0
*/
void setPlaceholderText(const QString &message);
/**
* Sets the stylesheet used to control the visual display of this LineEdit
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* Sets the line edit wrapped by this LineEdit (widget must inherit KLineEdit), ownership is transferred to the LineEdit
*
* @param nativeWidget line edit that will be wrapped by this LineEdit
* @since KDE4.4
*/
void setNativeWidget(KLineEdit *nativeWidget);
/**
* @return the native widget wrapped by this LineEdit
*/
KLineEdit *nativeWidget() const;
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void changeEvent(QEvent *event);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void focusInEvent(QFocusEvent *event);
void focusOutEvent(QFocusEvent *event);
Q_SIGNALS:
void editingFinished();
void returnPressed();
void textEdited(const QString &text);
/**
* Emitted when the text changes
* @since 4.4
*/
void textChanged(const QString &text);
/**
* Emitted when the widget receives or loses focus
* @since 4.7
*/
void focusChanged(bool focused);
private:
Q_PRIVATE_SLOT(d, void setPalette())
LineEditPrivate *const d;
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,25 +0,0 @@
#!/bin/sh
# usage: make_widget LineEdit
LOWERNAME=`echo $1 | tr [:upper:] [:lower:]`
NAME=$1
CAPNAME=`echo $1 | tr [:lower:] [:upper:]`
NATIVE="Q${NAME}"
HEADER="${LOWERNAME}.h"
SOURCE="${LOWERNAME}.cpp"
BOTH="$HEADER $SOURCE"
QHEADER="Q${HEADER}"
cp widget.h.template $HEADER
cp widget.cpp.template $SOURCE
perl -pi -e "s,<Name>,${NAME},g" $BOTH
perl -pi -e "s,<NAME>,${CAPNAME},g" $BOTH
perl -pi -e "s,<name>,${LOWERNAME},g" $BOTH
perl -pi -e "s,<Native>,$NATIVE,g" $BOTH
echo "#include \"../../plasma/${HEADER}\"" > ../includes/${NAME}
svn add ../includes/${NAME} $BOTH

View File

@ -1,562 +0,0 @@
/*
* Copyright (C) 2007 Petri Damsten <damu@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "meter.h"
#include "private/meter_p.h"
#include <cmath>
#include <QPainter>
#include <QTimeLine>
#include <QPropertyAnimation>
#include <kdebug.h>
#include <kglobalsettings.h>
#include "plasma/animator.h"
#include "plasma/framesvg.h"
#include "plasma/theme.h"
namespace Plasma {
MeterPrivate::MeterPrivate(Meter *m)
: QObject(m),
minimum(0),
maximum(100),
value(0),
targetValue(0),
meterType(Meter::AnalogMeter),
image(0),
minrotate(0),
maxrotate(360),
meter(m)
{
}
void MeterPrivate::progressChanged(int progress)
{
value = progress;
meter->update();
}
void MeterPrivate::paint(QPainter *p, const QString &elementID)
{
if (image->hasElement(elementID)) {
QRectF elementRect = image->elementRect(elementID);
image->paint(p, elementRect, elementID);
}
}
void MeterPrivate::text(QPainter *p, int index)
{
QString elementID = QString("label%1").arg(index);
QString text = labels[index];
if (image->hasElement(elementID)) {
QRectF elementRect = image->elementRect(elementID);
Qt::Alignment align = Qt::AlignCenter;
if (colors.count() > index) {
p->setPen(QPen(colors[index]));
} else {
p->setPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
}
if (fonts.count() > index) {
p->setFont(fonts[index]);
}
QFontMetricsF fm(p->font());
// If the height is too small increase the Height of the button to shall the whole text #192988
if (elementRect.height() < fm.height()) {
QPointF oldCenter = elementRect.center();
elementRect.setHeight(fm.height());
elementRect.moveCenter(oldCenter);
}
if (alignments.count() > index) {
align = alignments[index];
}
if (elementRect.width() > elementRect.height()) {
if (align&Qt::AlignLeft) {
p->drawText(elementRect.bottomLeft(), text);
} else {
p->drawText(elementRect, align, text);
}
} else {
p->save();
QPointF rotateCenter(
elementRect.left() + elementRect.width() / 2,
elementRect.top() + elementRect.height() / 2);
p->translate(rotateCenter);
p->rotate(-90);
p->translate(elementRect.height() / -2,
elementRect.width() / -2);
QRectF r(0, 0, elementRect.height(), elementRect.width());
p->drawText(r, align, text);
p->restore();
}
}
}
QRectF MeterPrivate::barRect()
{
QRectF elementRect;
if (labels.count() > 0) {
elementRect = image->elementRect("background");
} else {
elementRect = QRectF(QPoint(0,0), meter->size());
}
if (image->hasElement("hint-bar-stretch") || !image->hasElement("bar-active-center")) {
return elementRect;
}
QSize imageSize = image->size();
image->resize();
QSize tileSize = image->elementSize("bar-active-center");
image->resize(imageSize);
if (elementRect.width() > elementRect.height()) {
qreal ratio = qMax(1, tileSize.height() / tileSize.width());
int numTiles = qMax(qreal(1.0), qreal(elementRect.width())/(qreal(elementRect.height())/ratio));
tileSize = QSize(elementRect.width()/numTiles, elementRect.height());
QPoint center = elementRect.center().toPoint();
elementRect.setWidth(tileSize.width()*numTiles);
elementRect.moveCenter(center);
} else {
qreal ratio = qMax(1, tileSize.width() / tileSize.height());
int numTiles = qMax(qreal(1.0), qreal(elementRect.height())/(qreal(elementRect.width())/ratio));
tileSize = QSize(elementRect.width(), elementRect.height()/numTiles);
QPoint center = elementRect.center().toPoint();
elementRect.setHeight(tileSize.height()*numTiles);
elementRect.moveCenter(center);
}
return elementRect;
}
void MeterPrivate::paintBackground(QPainter *p)
{
//be retrocompatible with themes for kde <= 4.1
if (image->hasElement("background-center")) {
QRectF elementRect = barRect();
if (elementRect.isEmpty()) {
return; // nothing to be done
}
QSize imageSize = image->size();
image->resize();
image->setElementPrefix("background");
image->resizeFrame(elementRect.size());
image->paintFrame(p, elementRect.topLeft());
image->resize(imageSize);
paintBar(p, "bar-inactive");
} else {
paint(p, "background");
}
}
void MeterPrivate::paintBar(QPainter *p, const QString &prefix)
{
QRectF elementRect = barRect();
image->setUsingRenderingCache(false);
if (image->hasElement("hint-bar-stretch")) {
const QSize imageSize = image->size();
image->resize();
image->setElementPrefix(prefix);
image->resizeFrame(elementRect.size());
image->paintFrame(p, elementRect.topLeft());
image->resize(imageSize);
} else {
const QSize imageSize = image->size();
image->resize();
QSize tileSize = image->elementSize("bar-active-center");
if (elementRect.width() > elementRect.height()) {
qreal ratio = tileSize.height() / tileSize.width();
int numTiles = elementRect.width()/(elementRect.height()/ratio);
tileSize = QSize(elementRect.width()/numTiles, elementRect.height());
} else {
qreal ratio = tileSize.width() / tileSize.height();
int numTiles = elementRect.height()/(elementRect.width()/ratio);
tileSize = QSize(elementRect.width(), elementRect.height()/numTiles);
}
image->setElementPrefix(prefix);
image->resizeFrame(tileSize);
p->drawTiledPixmap(elementRect, image->framePixmap());
image->resize(imageSize);
}
image->setUsingRenderingCache(true);
}
void MeterPrivate::paintForeground(QPainter *p)
{
for (int i = 0; i < labels.count(); ++i) {
text(p, i);
}
paint(p, "foreground");
}
void MeterPrivate::setSizePolicyAndPreferredSize()
{
switch (meterType) {
case Meter::BarMeterHorizontal:
meter->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
break;
case Meter::BarMeterVertical:
meter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
break;
case Meter::AnalogMeter:
default:
meter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
break;
}
if (image) {
//set a sane preferredSize. We can't just use the svg's native size, since that way
//letters get cut off if the user uses a font larger then usual. Check how many rows of
//labels we have, add 1 (the progress bar), and multiply by the font height to get a
//somewhat sane size height. This is not perfect but work well enough for 4.2. I suggest
//we look into alternatives for 4.3.
uint i = 0;
uint rows = 0;
qreal prevY = -1;
QString labelName = "label0";
while (image->hasElement(labelName)) {
if (image->elementRect(labelName).y() > prevY) {
prevY = image->elementRect(labelName).y();
rows++;
}
i++;
labelName = QString("label%0").arg(i);
}
Plasma::Theme *theme = Plasma::Theme::defaultTheme();
QFont font = theme->font(Plasma::Theme::DefaultFont);
QFontMetrics fm(font);
meter->setPreferredHeight((rows + 1) * fm.height());
} else {
meter->setPreferredSize(QSizeF(30, 30));
}
}
Meter::Meter(QGraphicsItem *parent) :
QGraphicsWidget(parent),
d(new MeterPrivate(this))
{
d->setSizePolicyAndPreferredSize();
d->animation = new QPropertyAnimation(d, "meterValue");
}
Meter::~Meter()
{
delete d->animation;
delete d;
}
void Meter::setMaximum(int maximum)
{
d->maximum = maximum;
}
int Meter::maximum() const
{
return d->maximum;
}
void Meter::setMinimum(int minimum)
{
d->minimum = minimum;
}
int Meter::minimum() const
{
return d->minimum;
}
int Meter::value() const
{
return d->value;
}
void Meter::setValue(int value)
{
if (value == d->targetValue) {
return;
}
d->targetValue = qBound(d->minimum, value, d->maximum);
int delta = abs(d->value - d->targetValue);
if (d->animation->state() != QAbstractAnimation::Running) {
d->animation->stop();
}
//kDebug() << d->targetValue << d->value << delta;
if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects) ||
delta / qreal(d->maximum) < 0.1) {
d->value = value;
update();
} else {
d->animation->setStartValue(d->value);
d->animation->setEndValue(value);
d->animation->start();
}
emit valueChanged(value);
}
int MeterPrivate::meterValue() const
{
return value;
}
void MeterPrivate::setMeterValue(int value)
{
progressChanged(value);
}
void Meter::setLabel(int index, const QString &text)
{
while (d->labels.count() <= index) {
d->labels << QString();
}
d->labels[index] = text;
}
QString Meter::label(int index) const
{
return d->labels[index];
}
void Meter::setLabelColor(int index, const QColor &color)
{
while (d->colors.count() <= index) {
d->colors << color;
}
d->colors[index] = color;
}
QColor Meter::labelColor(int index) const
{
return d->colors[index];
}
void Meter::setLabelFont(int index, const QFont &font)
{
while (d->fonts.count() <= index) {
d->fonts << font;
}
d->fonts[index] = font;
}
QFont Meter::labelFont(int index) const
{
return d->fonts[index];
}
void Meter::setLabelAlignment(int index, const Qt::Alignment alignment)
{
while (d->alignments.count() <= index) {
d->alignments << alignment;
}
d->alignments[index] = alignment;
}
Qt::Alignment Meter::labelAlignment(int index) const
{
return d->alignments[index];
}
QRectF Meter::labelRect(int index) const
{
QString elementID = QString("label%1").arg(index);
return d->image->elementRect(elementID);
}
void Meter::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
{
Q_UNUSED(sourceName)
foreach (const QVariant &v, data) {
if (v.type() == QVariant::Int ||
v.type() == QVariant::UInt ||
v.type() == QVariant::LongLong ||
v.type() == QVariant::ULongLong) {
setValue(v.toInt());
return;
}
}
}
void Meter::setSvg(const QString &svg)
{
if (d->svg == svg) {
return;
}
d->svg = svg;
delete d->image;
d->image = new Plasma::FrameSvg(this);
d->image->setImagePath(svg);
// To create renderer and get default size
d->image->resize();
d->setSizePolicyAndPreferredSize();
if (d->image->hasElement("rotateminmax")) {
QRectF r = d->image->elementRect("rotateminmax");
d->minrotate = (int)r.height();
d->maxrotate = (int)r.width();
}
}
QString Meter::svg() const
{
return d->svg;
}
void Meter::setMeterType(MeterType meterType)
{
d->meterType = meterType;
if (d->svg.isEmpty()) {
if (meterType == BarMeterHorizontal) {
setSvg("widgets/bar_meter_horizontal");
} else if (meterType == BarMeterVertical) {
setSvg("widgets/bar_meter_vertical");
} else if (meterType == AnalogMeter) {
setSvg("widgets/analog_meter");
}
}
d->setSizePolicyAndPreferredSize();
}
Meter::MeterType Meter::meterType() const
{
return d->meterType;
}
void Meter::paint(QPainter *p,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
if (d->svg.isEmpty()) {
setMeterType(d->meterType);
}
if (!d->image) {
return;
}
QRectF rect(QPointF(0, 0), size());
QRectF clipRect;
qreal percentage = 0.0;
qreal angle = 0.0;
QPointF rotateCenter;
QSize intSize = QSize((int)size().width(), (int)size().height());
if (intSize != d->image->size()) {
d->image->resize(intSize);
}
if (d->maximum != d->minimum) {
percentage = (qreal)(d->value - d->minimum) / (d->maximum - d->minimum);
}
p->setRenderHint(QPainter::SmoothPixmapTransform);
switch (d->meterType) {
case BarMeterHorizontal:
case BarMeterVertical:
d->paintBackground(p);
p->save();
clipRect = d->barRect();
if (clipRect.width() > clipRect.height()) {
clipRect.setWidth(clipRect.width() * percentage);
} else {
qreal bottom = clipRect.bottom();
clipRect.setHeight(clipRect.height() * percentage);
clipRect.moveBottom(bottom);
}
p->setClipRect(clipRect, Qt::IntersectClip);
//be retrocompatible
if (d->image->hasElement("bar-active-center")) {
d->paintBar(p, "bar-active");
} else {
d->paint(p, "bar");
}
p->restore();
d->paintForeground(p);
break;
case AnalogMeter:
d->paintBackground(p);
p->save();
if (d->image->hasElement("rotatecenter")) {
QRectF r = d->image->elementRect("rotatecenter");
rotateCenter = QPointF(r.left() + r.width() / 2,
r.top() + r.height() / 2);
} else {
rotateCenter = QPointF(rect.width() / 2, rect.height() / 2);
}
angle = percentage * (d->maxrotate - d->minrotate) + d->minrotate;
if (d->image->hasElement("pointer-shadow")) {
p->save();
p->translate(rotateCenter+QPoint(2,3));
p->rotate(angle);
p->translate(-1 * rotateCenter);
d->paint(p, "pointer-shadow");
p->restore();
}
p->translate(rotateCenter);
p->rotate(angle);
p->translate(-1 * rotateCenter);
d->paint(p, "pointer");
p->restore();
d->paintForeground(p);
break;
}
}
QSizeF Meter::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
return QGraphicsWidget::sizeHint(which, constraint);
}
} // End of namepace
#include "moc_meter.cpp"
#include "../private/moc_meter_p.cpp"

View File

@ -1,226 +0,0 @@
/*
* Copyright (C) 2007 Petri Damsten <damu@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_METER_H
#define PLASMA_METER_H
#include <plasma/plasma_export.h>
#include <plasma/dataengine.h>
#include <QGraphicsWidget>
namespace Plasma
{
class MeterPrivate;
/**
* @class Meter plasma/widgets/meter.h <Plasma/Widgets/Meter>
*
* @short Provides generic meter widget for Plasma
*
* Analog and bar meters are supported.
*
* Svgs can have following ids:
* - background: Drawn first to the bottom
* background can be a FrameSvg
* - label0, label1, ...: Rectangles mark the label places
* - bar: Bar for the bar meter
* can be replaced with bar-active and bar-inactive FrameSvg
* - pointer: Pointer for analog meter
* - rotatecenter: Marks the place of pointer rotation center
* - rotateminmax: Width and height of this object are the Min and Max rotate
* angles for the pointer
* - foreground: Is drawn to top
*
* @author Petri Damstén
*/
class PLASMA_EXPORT Meter : public QGraphicsWidget
{
Q_OBJECT
Q_ENUMS(MeterType)
Q_PROPERTY(int minimum READ minimum WRITE setMinimum)
Q_PROPERTY(int maximum READ maximum WRITE setMaximum)
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(QString svg READ svg WRITE setSvg)
Q_PROPERTY(MeterType meterType READ meterType WRITE setMeterType)
public:
/**
* Meter types enum
*/
enum MeterType {
/** Horizontal bar meter (like thermometer). */
BarMeterHorizontal,
/** Vertical bar meter (like thermometer). */
BarMeterVertical,
/** Analog meter (like tachometer). */
AnalogMeter
};
/**
* Constructor
* @param parent the QGraphicsItem this meter is parented to.
* @param parent the QObject this meter is parented to.
*/
explicit Meter(QGraphicsItem *parent = 0);
/**
* Destructor
*/
~Meter();
/**
* @return maximum value for the meter
*/
int maximum() const;
/**
* @return minimum value for the meter
*/
int minimum() const;
/**
* @return value for the meter
*/
int value() const;
/**
* Set svg file name
*/
void setSvg(const QString &svg);
/**
* @return svg file name
*/
QString svg() const;
/**
* Set meter type. Note: setSvg gets called automatically with the proper
* default values if svg is not set.
*/
void setMeterType(MeterType type);
/**
* @return meter type
*/
MeterType meterType() const;
/**
* Set text label for the meter
* @param index label index.
* @param text text for the label.
*/
void setLabel(int index, const QString &text);
/**
* @param index label index
* @return text label for the meter
*/
QString label(int index) const;
/**
* Set text label color for the meter
* @param index label index
* @param color the color to apply to the label
*/
void setLabelColor(int index, const QColor &color);
/**
* @param index label index
* @return text label color for the meter
*/
QColor labelColor(int index) const;
/**
* Set text label font for the meter
* @param index label index
* @param font the font to apply to the label
*/
void setLabelFont(int index, const QFont &font);
/**
* @param index label index
* @return text label font for the meter
*/
QFont labelFont(int index) const;
/**
* Set text label alignment for the meter
* @param index label index
* @param alignment the text alignment to apply to the label
*/
void setLabelAlignment(int index, const Qt::Alignment alignment);
/**
* @param index label index
* @return text label alignment for the meter
*/
Qt::Alignment labelAlignment(int index) const;
/**
* @param index label index
* @return the size of this label.
*/
QRectF labelRect(int index) const;
public Q_SLOTS:
/**
* Used when connecting to a DataEngine
*/
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
/**
* Set maximum value for the meter
*/
void setMaximum(int maximum);
/**
* Set minimum value for the meter
*/
void setMinimum(int minimum);
/**
* Set value for the meter
*/
void setValue(int value);
Q_SIGNALS:
/**
* This signal is sent when the value of the meter changes programmatically.
* The meter's value is passed.
*/
void valueChanged(const int &value);
protected:
/**
* Reimplemented from Plasma::Widget
*/
virtual void paint(QPainter *p,
const QStyleOptionGraphicsItem *option,
QWidget *widget = 0);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
private:
MeterPrivate *const d;
};
} // End of namepace
#endif

View File

@ -1,538 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
* Copyright 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "pushbutton.h"
#include <QDir>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QWeakPointer>
#include <kiconeffect.h>
#include <kiconloader.h>
#include <qmimedatabase.h>
#include <kpushbutton.h>
#include "animator.h"
#include "animations/animation.h"
#include "framesvg.h"
#include "paintutils.h"
#include "private/actionwidgetinterface_p.h"
#include "graphicsview/private/focusindicator_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
class PushButtonPrivate : public ActionWidgetInterface<PushButton>
{
public:
PushButtonPrivate(PushButton *pushButton)
: ActionWidgetInterface<PushButton>(pushButton),
background(0),
fadeIn(false),
svg(0)
{
}
~PushButtonPrivate()
{
delete svg;
}
void setPixmap()
{
if (imagePath.isEmpty()) {
delete svg;
svg = 0;
return;
}
QMimeDatabase db;
QMimeType mime = db.mimeTypeForFile(absImagePath);
QPixmap pm;
if (mime.inherits("image/svg+xml") || mime.inherits("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != absImagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
if (!svgElement.isNull()) {
svg->setContainsMultipleImages(true);
}
}
//QPainter p(&pm);
if (!svgElement.isEmpty() && svg->hasElement(svgElement)) {
svg->resize();
QSizeF elementSize = svg->elementSize(svgElement);
float scale = q->nativeWidget()->iconSize().width() / qMax(elementSize.width(), elementSize.height());
svg->resize(elementSize * scale);
pm = svg->pixmap(svgElement);
} else {
svg->resize(q->nativeWidget()->iconSize());
pm = svg->pixmap();
}
} else {
delete svg;
svg = 0;
pm = QPixmap(absImagePath);
}
static_cast<KPushButton*>(q->widget())->setIcon(QIcon(pm));
}
void pressedChanged()
{
if (q->nativeWidget()->isDown() || q->nativeWidget()->isChecked()) {
focusIndicator->animateVisibility(false);
} else {
focusIndicator->animateVisibility(true);
}
}
void syncFrame()
{
if (background) {
//resize all panels
background->setElementPrefix("pressed");
background->resizeFrame(q->size());
syncActiveRect();
background->setElementPrefix("normal");
background->resizeFrame(q->size());
hoverAnimation->setProperty("startPixmap", background->framePixmap());
background->setElementPrefix("active");
background->resizeFrame(activeRect.size());
hoverAnimation->setProperty("targetPixmap", background->framePixmap());
}
}
void syncActiveRect();
void syncBorders();
FrameSvg *background;
bool fadeIn;
qreal opacity;
QRectF activeRect;
Animation *hoverAnimation;
FocusIndicator *focusIndicator;
QString imagePath;
QString absImagePath;
Svg *svg;
QString svgElement;
};
void PushButtonPrivate::syncActiveRect()
{
background->setElementPrefix("normal");
qreal left, top, right, bottom;
background->getMargins(left, top, right, bottom);
background->setElementPrefix("active");
qreal activeLeft, activeTop, activeRight, activeBottom;
background->getMargins(activeLeft, activeTop, activeRight, activeBottom);
activeRect = QRectF(QPointF(0, 0), q->size());
activeRect.adjust(left - activeLeft, top - activeTop,
-(right - activeRight), -(bottom - activeBottom));
background->setElementPrefix("normal");
}
void PushButtonPrivate::syncBorders()
{
//set margins from the normal element
qreal left, top, right, bottom;
background->setElementPrefix("normal");
background->getMargins(left, top, right, bottom);
q->setContentsMargins(left, top, right, bottom);
//calc the rect for the over effect
syncActiveRect();
}
PushButton::PushButton(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new PushButtonPrivate(this))
{
d->background = new FrameSvg(this);
d->background->setImagePath("widgets/button");
d->background->setCacheAllRenderedFrames(true);
d->background->setElementPrefix("normal");
d->hoverAnimation = Animator::create(Animator::PixmapTransitionAnimation);
d->hoverAnimation->setTargetWidget(this);
KPushButton *native = new KPushButton;
connect(native, SIGNAL(pressed()), this, SIGNAL(pressed()));
connect(native, SIGNAL(pressed()), this, SLOT(pressedChanged()));
connect(native, SIGNAL(released()), this, SIGNAL(released()));
connect(native, SIGNAL(released()), this, SLOT(pressedChanged()));
connect(native, SIGNAL(clicked()), this, SIGNAL(clicked()));
connect(native, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
setWidget(native);
native->setAttribute(Qt::WA_NoSystemBackground);
native->setWindowIcon(QIcon());
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
d->focusIndicator = new FocusIndicator(this, d->background);
d->syncBorders();
setAcceptHoverEvents(true);
connect(d->background, SIGNAL(repaintNeeded()), SLOT(syncBorders()));
d->initTheming();
d->syncFrame();
}
PushButton::~PushButton()
{
delete d;
}
void PushButton::setText(const QString &text)
{
static_cast<KPushButton*>(widget())->setText(text);
updateGeometry();
}
QString PushButton::text() const
{
return static_cast<KPushButton*>(widget())->text();
}
void PushButton::setImage(const QString &path)
{
if (d->imagePath == path) {
return;
}
delete d->svg;
d->svg = 0;
d->imagePath = path;
bool absolutePath = !path.isEmpty() &&
#ifdef Q_OS_WIN
!QDir::isRelativePath(path)
#else
(path[0] == '/' || path.startsWith(QLatin1String(":/")))
#endif
;
if (absolutePath) {
d->absImagePath = path;
} else {
//TODO: package support
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap();
}
void PushButton::setImage(const QString &path, const QString &elementid)
{
d->svgElement = elementid;
setImage(path);
}
QString PushButton::image() const
{
return d->imagePath;
}
void PushButton::setStyleSheet(const QString &stylesheet)
{
d->focusIndicator->setVisible(stylesheet.isEmpty());
widget()->setStyleSheet(stylesheet);
}
QString PushButton::styleSheet()
{
return widget()->styleSheet();
}
void PushButton::setAction(QAction *action)
{
d->setAction(action);
}
QAction *PushButton::action() const
{
return d->action;
}
void PushButton::setIcon(const QIcon &icon)
{
nativeWidget()->setIcon(icon);
}
QIcon PushButton::icon() const
{
return nativeWidget()->icon();
}
void PushButton::setCheckable(bool checkable)
{
nativeWidget()->setCheckable(checkable);
}
bool PushButton::isCheckable() const
{
return nativeWidget()->isCheckable();
}
void PushButton::setChecked(bool checked)
{
nativeWidget()->setChecked(checked);
}
void PushButton::click()
{
nativeWidget()->animateClick();
}
bool PushButton::isChecked() const
{
return nativeWidget()->isChecked();
}
bool PushButton::isDown() const
{
return nativeWidget()->isDown();
}
KPushButton *PushButton::nativeWidget() const
{
return static_cast<KPushButton*>(widget());
}
void PushButton::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap();
d->syncFrame();
QGraphicsProxyWidget::resizeEvent(event);
}
void PushButton::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
if (!styleSheet().isNull() || Theme::defaultTheme()->useNativeWidgetStyle()) {
QGraphicsProxyWidget::paint(painter, option, widget);
return;
}
QPixmap bufferPixmap;
//Normal button, pressed or not
if (isEnabled()) {
if (nativeWidget()->isDown() || nativeWidget()->isChecked()) {
d->background->setElementPrefix("pressed");
} else {
d->background->setElementPrefix("normal");
}
//flat or disabled
} else if (!isEnabled() || nativeWidget()->isFlat()) {
bufferPixmap = QPixmap(rect().size().toSize());
bufferPixmap.fill(Qt::transparent);
QPainter buffPainter(&bufferPixmap);
d->background->paintFrame(&buffPainter);
buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
buffPainter.fillRect(bufferPixmap.rect(), QColor(0, 0, 0, 128));
painter->drawPixmap(0, 0, bufferPixmap);
}
//if is under mouse draw the animated glow overlay
if (!nativeWidget()->isDown() && !nativeWidget()->isChecked() && isEnabled() && acceptHoverEvents() && d->background->hasElementPrefix("active")) {
if (d->hoverAnimation->state() == QAbstractAnimation::Running && !isUnderMouse() && !nativeWidget()->isDefault()) {
d->background->setElementPrefix("active");
d->background->paintFrame(painter, d->activeRect.topLeft());
} else {
painter->drawPixmap(
d->activeRect.topLeft(),
d->hoverAnimation->property("currentPixmap").value<QPixmap>());
}
} else if (isEnabled()) {
d->background->paintFrame(painter);
}
painter->setPen(Plasma::Theme::defaultTheme()->color(Theme::ButtonTextColor));
if (nativeWidget()->isDown()) {
painter->translate(QPoint(1, 1));
}
QRectF rect = contentsRect();
if (!nativeWidget()->icon().isNull()) {
const qreal iconSize = qMin(rect.width(), rect.height());
QPixmap iconPix = nativeWidget()->icon().pixmap(iconSize);
if (!isEnabled()) {
KIconEffect *effect = KIconLoader::global()->iconEffect();
iconPix = effect->apply(iconPix, KIconLoader::Toolbar, KIconLoader::DisabledState);
}
QRect pixmapRect;
if (nativeWidget()->text().isEmpty()) {
pixmapRect = nativeWidget()->style()->alignedRect(option->direction, Qt::AlignCenter, iconPix.size(), rect.toRect());
} else {
pixmapRect = nativeWidget()->style()->alignedRect(option->direction, Qt::AlignLeft|Qt::AlignVCenter, iconPix.size(), rect.toRect());
}
painter->drawPixmap(pixmapRect.topLeft(), iconPix);
if (option->direction == Qt::LeftToRight) {
rect.adjust(rect.height(), 0, 0, 0);
} else {
rect.adjust(0, 0, -rect.height(), 0);
}
}
QFontMetricsF fm(font());
// If the height is too small increase the Height of the button to shall the whole text #192988
if (rect.height() < fm.height()) {
rect.setHeight(fm.height());
rect.moveTop(boundingRect().center().y() - rect.height() / 2);
}
// If there is not enough room for the text make it to fade out
if (rect.width() < fm.width(nativeWidget()->text())) {
if (bufferPixmap.isNull()) {
bufferPixmap = QPixmap(rect.size().toSize());
}
bufferPixmap.fill(Qt::transparent);
QPainter p(&bufferPixmap);
p.setPen(painter->pen());
p.setFont(font());
// Create the alpha gradient for the fade out effect
QLinearGradient alphaGradient(0, 0, 1, 0);
alphaGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
if (option->direction == Qt::LeftToRight) {
alphaGradient.setColorAt(0, QColor(0, 0, 0, 255));
alphaGradient.setColorAt(1, QColor(0, 0, 0, 0));
p.drawText(bufferPixmap.rect(), Qt::AlignLeft|Qt::AlignVCenter|Qt::TextShowMnemonic,
nativeWidget()->text());
} else {
alphaGradient.setColorAt(0, QColor(0, 0, 0, 0));
alphaGradient.setColorAt(1, QColor(0, 0, 0, 255));
p.drawText(bufferPixmap.rect(), Qt::AlignRight|Qt::AlignVCenter|Qt::TextShowMnemonic,
nativeWidget()->text());
}
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
p.fillRect(bufferPixmap.rect(), alphaGradient);
painter->drawPixmap(rect.topLeft(), bufferPixmap);
} else {
painter->setFont(font());
painter->drawText(rect, Qt::AlignCenter|Qt::TextShowMnemonic, nativeWidget()->text());
}
}
void PushButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
if (nativeWidget()->isDown() || d->background->hasElementPrefix("hover")) {
return;
}
d->hoverAnimation->setProperty("duration", 75);
d->background->setElementPrefix("normal");
d->hoverAnimation->setProperty("startPixmap", d->background->framePixmap());
d->background->setElementPrefix("active");
d->hoverAnimation->setProperty("targetPixmap", d->background->framePixmap());
d->hoverAnimation->start();
QGraphicsProxyWidget::hoverEnterEvent(event);
}
void PushButton::changeEvent(QEvent *event)
{
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}
void PushButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
if (nativeWidget()->isDown() || d->background->hasElementPrefix("hover")) {
return;
}
d->hoverAnimation->setProperty("duration", 150);
d->background->setElementPrefix("active");
d->hoverAnimation->setProperty("startPixmap", d->background->framePixmap());
d->background->setElementPrefix("normal");
d->hoverAnimation->setProperty("targetPixmap", d->background->framePixmap());
d->hoverAnimation->start();
QGraphicsProxyWidget::hoverLeaveEvent(event);
}
QSizeF PushButton::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
{
QSizeF hint = QGraphicsProxyWidget::sizeHint(which, constraint);
if (hint.isEmpty()) {
return hint;
}
//replace the native margin with the Svg one
QStyleOption option;
option.initFrom(nativeWidget());
int nativeMargin = nativeWidget()->style()->pixelMetric(QStyle::PM_ButtonMargin, &option, nativeWidget());
qreal left, top, right, bottom;
d->background->getMargins(left, top, right, bottom);
hint = hint - QSize(nativeMargin, nativeMargin) + QSize(left+right, top+bottom);
return hint;
}
} // namespace Plasma
#include "moc_pushbutton.cpp"

View File

@ -1,233 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_PUSHBUTTON_H
#define PLASMA_PUSHBUTTON_H
#include <QGraphicsProxyWidget>
class KPushButton;
#include <plasma/plasma_export.h>
namespace Plasma
{
class PushButtonPrivate;
/**
* @class PushButton plasma/widgets/pushbutton.h <Plasma/Widgets/PushButton>
*
* @short Provides a plasma-themed KPushButton.
*/
class PLASMA_EXPORT PushButton : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(KPushButton *nativeWidget READ nativeWidget)
Q_PROPERTY(QAction *action READ action WRITE setAction)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable)
Q_PROPERTY(bool checked READ isChecked WRITE setChecked)
Q_PROPERTY(bool down READ isDown)
public:
explicit PushButton(QGraphicsWidget *parent = 0);
~PushButton();
/**
* Sets the display text for this PushButton
*
* @param text the text to display; should be translated.
*/
void setText(const QString &text);
/**
* @return the display text
*/
QString text() const;
/**
* Sets the path to an image to display.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
*/
void setImage(const QString &path);
/**
* Sets the path to an svg image to display and the id of the used svg element, if necessary.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
* @param elementid the id of a svg element.
*
* @since 4.4
*/
void setImage(const QString &path, const QString &elementid);
/**
* @return the image path being displayed currently, or an empty string if none.
*/
QString image() const;
/**
* Sets the stylesheet used to control the visual display of this PushButton
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* Associate an action with this IconWidget
* this makes the button follow the state of the action, using its icon, text, etc.
* when the button is clicked, it will also trigger the action.
*
* @since 4.3
*/
void setAction(QAction *action);
/**
* @return the currently associated action, if any.
*
* @since 4.3
*/
QAction *action() const;
/**
* sets the icon for this push button using a KDE::icon
*
* @param icon the icon to use
*
* @since 4.4
*/
void setIcon(const QIcon &icon);
/**
* @return the icon of this button
*
* @since 4.3
*/
QIcon icon() const;
/**
* Sets whether or not this button can be toggled on/off
*
* @since 4.3
*/
void setCheckable(bool checkable);
/**
* @return true if the button is checkable
* @see setCheckable
* @since 4.4
*/
bool isCheckable() const;
/**
* @return true if the button is checked; requires setIsCheckable(true) to
* be called
*
* @since 4.3
*/
bool isChecked() const;
/**
* @return true if the button is pressed down
* @since 4.4
*/
bool isDown() const;
/**
* @return the native widget wrapped by this PushButton
*/
KPushButton *nativeWidget() const;
Q_SIGNALS:
/**
* Emitted when the button is pressed down; usually the clicked() signal
* will suffice, however.
* @since 4.4
*/
void pressed();
/**
* Emitted when the button is released; usually the clicked() signal
* will suffice, however.
* @since 4.4
*/
void released();
/**
* Emitted when the button is pressed then released, completing a click
*/
void clicked();
/**
* Emitted when the button changes state from up to down
*/
void toggled(bool);
public Q_SLOTS:
/**
* Performs a visual click and emits the associated signals
* @since 4.6
*/
void click();
/**
* Sets whether or not this button is checked. Implies setIsCheckable(true).
*
* @since 4.3
*/
void setChecked(bool checked);
protected:
void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget = 0);
void resizeEvent(QGraphicsSceneResizeEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void changeEvent(QEvent *event);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const;
private:
Q_PRIVATE_SLOT(d, void syncBorders())
Q_PRIVATE_SLOT(d, void setPixmap())
Q_PRIVATE_SLOT(d, void pressedChanged())
Q_PRIVATE_SLOT(d, void syncToAction())
Q_PRIVATE_SLOT(d, void clearAction())
Q_PRIVATE_SLOT(d, void setPalette())
friend class PushButtonPrivate;
PushButtonPrivate *const d;
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,177 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "radiobutton.h"
#include <QDir>
#include <QPainter>
#include <QRadioButton>
#include <qmimedatabase.h>
#include "private/themedwidgetinterface_p.h"
#include "svg.h"
#include "theme.h"
namespace Plasma
{
class RadioButtonPrivate : public ThemedWidgetInterface<RadioButton>
{
public:
RadioButtonPrivate(RadioButton *radio)
: ThemedWidgetInterface<RadioButton>(radio),
svg(0)
{
}
~RadioButtonPrivate()
{
delete svg;
}
void setPixmap(RadioButton *q)
{
if (imagePath.isEmpty()) {
return;
}
QMimeDatabase db;
QMimeType mime = db.mimeTypeForFile(absImagePath);
QPixmap pm(q->size().toSize());
if (mime.inherits("image/svg+xml")) {
svg = new Svg();
QPainter p(&pm);
svg->paint(&p, pm.rect());
} else {
pm = QPixmap(absImagePath);
}
static_cast<QRadioButton*>(q->widget())->setIcon(QIcon(pm));
}
QString imagePath;
QString absImagePath;
Svg *svg;
};
RadioButton::RadioButton(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new RadioButtonPrivate(this))
{
QRadioButton *native = new QRadioButton;
connect(native, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
d->setWidget(native);
native->setWindowIcon(QIcon());
native->setAttribute(Qt::WA_NoSystemBackground);
d->initTheming();
}
RadioButton::~RadioButton()
{
delete d;
}
void RadioButton::setText(const QString &text)
{
static_cast<QRadioButton*>(widget())->setText(text);
}
QString RadioButton::text() const
{
return static_cast<QRadioButton*>(widget())->text();
}
void RadioButton::setImage(const QString &path)
{
if (d->imagePath == path) {
return;
}
delete d->svg;
d->svg = 0;
d->imagePath = path;
bool absolutePath = !path.isEmpty() &&
#ifdef Q_OS_WIN
!QDir::isRelativePath(path)
#else
(path[0] == '/' || path.startsWith(QLatin1String(":/")))
#endif
;
if (absolutePath) {
d->absImagePath = path;
} else {
//TODO: package support
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap(this);
}
QString RadioButton::image() const
{
return d->imagePath;
}
void RadioButton::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString RadioButton::styleSheet()
{
return widget()->styleSheet();
}
QRadioButton *RadioButton::nativeWidget() const
{
return static_cast<QRadioButton*>(widget());
}
void RadioButton::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap(this);
QGraphicsProxyWidget::resizeEvent(event);
}
void RadioButton::setChecked(bool checked)
{
static_cast<QRadioButton*>(widget())->setChecked(checked);
}
bool RadioButton::isChecked() const
{
return static_cast<QRadioButton*>(widget())->isChecked();
}
void RadioButton::changeEvent(QEvent *event)
{
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include "moc_radiobutton.cpp"

View File

@ -1,123 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_RADIOBUTTON_H
#define PLASMA_RADIOBUTTON_H
#include <QGraphicsProxyWidget>
class QRadioButton;
#include <plasma/plasma_export.h>
namespace Plasma
{
class RadioButtonPrivate;
/**
* @class RadioButton plasma/widgets/radiobutton.h <Plasma/Widgets/RadioButton>
*
* @short Provides a plasma-themed QRadioButton.
*/
class PLASMA_EXPORT RadioButton : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(QRadioButton *nativeWidget READ nativeWidget)
Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
public:
explicit RadioButton(QGraphicsWidget *parent = 0);
~RadioButton();
/**
* Sets the display text for this RadioButton
*
* @param text the text to display; should be translated.
*/
void setText(const QString &text);
/**
* @return the display text
*/
QString text() const;
/**
* Sets the path to an image to display.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
*/
void setImage(const QString &path);
/**
* @return the image path being displayed currently, or an empty string if none.
*/
QString image() const;
/**
* Sets the stylesheet used to control the visual display of this RadioButton
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* @return the native widget wrapped by this RadioButton
*/
QRadioButton *nativeWidget() const;
/**
* Sets the checked state.
*
* @param checked true if checked, false if not
*/
void setChecked(bool checked);
/**
* @return the checked state
*/
bool isChecked() const;
Q_SIGNALS:
void toggled(bool);
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event);
private:
Q_PRIVATE_SLOT(d, void setPixmap(RadioButton *))
RadioButtonPrivate * const d;
Q_PRIVATE_SLOT(d, void setPalette())
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,154 +0,0 @@
/*
* Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
* Copyright © 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "scrollbar.h"
#include <QApplication>
#include <QContextMenuEvent>
#include <QGraphicsSceneContextMenuEvent>
#include <plasma/graphicsview/private/style_p.h>
namespace Plasma
{
class ScrollBarPrivate
{
public:
Plasma::Style::Ptr style;
};
ScrollBar::ScrollBar(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new ScrollBarPrivate)
{
QScrollBar *scrollbar = new QScrollBar();
scrollbar->setWindowFlags(scrollbar->windowFlags()|Qt::BypassGraphicsProxyWidget);
scrollbar->setAttribute(Qt::WA_NoSystemBackground);
setWidget(scrollbar);
scrollbar->setWindowIcon(QIcon());
d->style = Plasma::Style::sharedStyle();
scrollbar->setStyle(d->style.data());
scrollbar->resize(scrollbar->sizeHint());
connect(scrollbar, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
connect(scrollbar, SIGNAL(sliderMoved(int)), this, SIGNAL(sliderMoved(int)));
}
ScrollBar::~ScrollBar()
{
delete d;
Plasma::Style::doneWithSharedStyle();
}
void ScrollBar::setRange(int min, int max)
{
static_cast<QScrollBar*>(widget())->setRange(min, max);
}
void ScrollBar::setSingleStep(int val)
{
static_cast<QScrollBar*>(widget())->setSingleStep(val);
}
int ScrollBar::singleStep()
{
return static_cast<QScrollBar*>(widget())->singleStep();
}
void ScrollBar::setPageStep(int val)
{
static_cast<QScrollBar*>(widget())->setPageStep(val);
}
int ScrollBar::pageStep()
{
return static_cast<QScrollBar*>(widget())->pageStep();
}
void ScrollBar::setValue(int val)
{
static_cast<QScrollBar*>(widget())->setValue(val);
}
int ScrollBar::value() const
{
return static_cast<QScrollBar*>(widget())->value();
}
int ScrollBar::minimum() const
{
return static_cast<QScrollBar*>(widget())->minimum();
}
int ScrollBar::maximum() const
{
return static_cast<QScrollBar*>(widget())->maximum();
}
void ScrollBar::setMinimum(const int min) const
{
static_cast<QScrollBar*>(widget())->setMinimum(min);
}
void ScrollBar::setMaximum(const int max) const
{
static_cast<QScrollBar*>(widget())->setMaximum(max);
}
void ScrollBar::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString ScrollBar::styleSheet()
{
return widget()->styleSheet();
}
QScrollBar *ScrollBar::nativeWidget() const
{
return static_cast<QScrollBar *>(widget());
}
Qt::Orientation ScrollBar::orientation() const
{
return nativeWidget()->orientation();
}
void ScrollBar::setOrientation(Qt::Orientation orientation)
{
QScrollBar *native = static_cast<QScrollBar *>(widget());
native->setOrientation(orientation);
resize(native->sizeHint());
}
void ScrollBar::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QContextMenuEvent contextMenuEvent(QContextMenuEvent::Reason(event->reason()),
event->pos().toPoint(), event->screenPos(), event->modifiers());
QApplication::sendEvent(nativeWidget(), &contextMenuEvent);
}
}
#include "moc_scrollbar.cpp"

View File

@ -1,173 +0,0 @@
/*
* Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
* Copyright © 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_SCROLLBAR_H
#define PLASMA_SCROLLBAR_H
#include <QScrollBar>
#include <QGraphicsProxyWidget>
#include <plasma/plasma_export.h>
namespace Plasma
{
class ScrollBarPrivate;
/**
* @class ScrollBar plasma/widgets/scrollbar.h <Plasma/Widgets/ScrollBar>
*
* @short Provides a plasma-themed QScrollBar.
*/
class PLASMA_EXPORT ScrollBar : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(int singleStep READ singleStep WRITE setSingleStep)
Q_PROPERTY(int pageStep READ pageStep WRITE setPageStep)
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(int minimum READ minimum WRITE setMinimum)
Q_PROPERTY(int maximum READ maximum WRITE setMaximum)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(QScrollBar *nativeWidget READ nativeWidget)
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
public:
/**
* Creates a scrollbar; the default orientation is vertical
*/
explicit ScrollBar(QGraphicsWidget *parent=0);
~ScrollBar();
/**
* Sets the scrollbar minimum and maximum values
* @param min minimum value
* @param max maximum value
*/
void setRange(int min, int max);
/**
* Sets the amount of the single step
* i.e how much the slider will move when the user press an arrow button
* @param val
*/
void setSingleStep(int val);
/**
* @return the amount of the single step
*/
int singleStep();
/**
* Sets the amount the slider will scroll when the user press page up or page down
* @param val
*/
void setPageStep(int val);
/**
* @return the amount of the page step
*/
int pageStep();
/**
* @return the current scrollbar value
*/
int value() const;
/**
* @return the minimum value bound of this ScrollBar
*/
int minimum() const;
/**
* @return the maximum value bound of this ScrollBar
*/
int maximum() const;
/**
* @param the minimum value bound of this ScrollBar
* @since 4.6
*/
void setMinimum(const int min) const;
/**
* @param the maximum value bound of this ScrollBar
* @since 4.6
*/
void setMaximum(const int max) const;
/**
* Sets the stylesheet used to control the visual display of this ScrollBar
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* @return the native widget wrapped by this ScrollBar
*/
QScrollBar *nativeWidget() const;
/**
* @return the orientation of the scrollbar
* @since 4.4
*/
Qt::Orientation orientation() const;
protected:
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
public Q_SLOTS:
/**
* Sets the current value for the ScrollBar
* @param value must be minimum() <= value <= maximum()
*/
void setValue(int val);
/**
* Sets the orientation of the ScrollBar.
*/
void setOrientation(Qt::Orientation orientation);
Q_SIGNALS:
/**
* Emitted when the value of the slider changes
*/
void valueChanged(int value);
/**
* Emitted when the slider has been moved by the user
* @since 4.6
*/
void sliderMoved(int value);
private:
ScrollBarPrivate * const d;
};
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,274 +0,0 @@
/*
* Copyright 2009 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_SCROLLWIDGET_H
#define PLASMA_SCROLLWIDGET_H
#include <QtCore/QAbstractAnimation>
#include <QGraphicsWidget>
#include <plasma/plasma_export.h>
namespace Plasma
{
class ScrollWidgetPrivate;
/**
* @class ScrollWidget plasma/widgets/ScrollWidget.h <Plasma/Widgets/ScrollWidget>
*
* @short A container of widgets that can have scrollbars
*
* A container of widgets that can have horizontal and vertical scrollbars if the content is bigger than the widget itself
*
* @since 4.3
*/
class PLASMA_EXPORT ScrollWidget : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *widget READ widget WRITE setWidget)
Q_PROPERTY(Qt::ScrollBarPolicy horizontalScrollBarPolicy READ horizontalScrollBarPolicy WRITE setHorizontalScrollBarPolicy)
Q_PROPERTY(Qt::ScrollBarPolicy verticalScrollBarPolicy READ verticalScrollBarPolicy WRITE setVerticalScrollBarPolicy)
Q_PROPERTY(bool overflowBordersVisible READ overflowBordersVisible WRITE setOverflowBordersVisible)
Q_PROPERTY(QPointF scrollPosition READ scrollPosition WRITE setScrollPosition)
Q_PROPERTY(QSizeF contentsSize READ contentsSize)
Q_PROPERTY(QRectF viewportGeometry READ viewportGeometry)
Q_PROPERTY(QSizeF snapSize READ snapSize WRITE setSnapSize)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
Q_PROPERTY(bool overShoot READ hasOverShoot WRITE setOverShoot)
public:
/**
* Constructs a new ScrollWidget
*
* @param parent the parent of this widget
*/
explicit ScrollWidget(QGraphicsWidget *parent = 0);
explicit ScrollWidget(QGraphicsItem *parent);
~ScrollWidget();
/**
* Sets the widget this ScrollWidget will contain
* ownership is transferred to this scrollwidget,
* if an old one was already in, it will be deleted.
* If the widget size policy allows for horizontal and/or vertical expansion,
* it will be resized when possible, otherwise it will be kept to whichever
* width the widget resizes itself.
*
* @param widget the new main sub widget
*/
void setWidget(QGraphicsWidget *widget);
/**
* @return the main widget
*/
QGraphicsWidget *widget() const;
/**
* Sets the alignment for the inner widget.
* It is only meaningful if the inner widget is smaller
* than the viewport.
* @since 4.5
*/
void setAlignment(Qt::Alignment align);
/**
* @return currently set alignment for the inner widget
* @since 4.5
*/
Qt::Alignment alignment() const;
/**
* Tells the scrollwidget whether the widget can scroll a little
* beyond its boundaries and then automatically snap back or
* whether the widget scrolling always stops at the edges.
* @since 4.5
*/
void setOverShoot(bool enable);
/**
* @return true if overshoot is enabled
* @since 4.5
*/
bool hasOverShoot() const;
/**
* Sets the horizontal scrollbar policy
*
* @param policy desired policy
*/
void setHorizontalScrollBarPolicy(const Qt::ScrollBarPolicy policy);
/**
* @return the horizontal scrollbar policy
*/
Qt::ScrollBarPolicy horizontalScrollBarPolicy() const;
/**
* Sets the vertical scrollbar policy
*
* @param policy desired policy
*/
void setVerticalScrollBarPolicy(const Qt::ScrollBarPolicy policy);
/**
* @return the vertical scrollbar policy
*/
Qt::ScrollBarPolicy verticalScrollBarPolicy() const;
/**
* @return true if the widget shows borders when the inner widget
* is bigger than the viewport
* @since 4.6
*/
bool overflowBordersVisible() const;
/**
* Sets whether borders should be shown when the inner widget
* is bigger than the viewport
* @param visible true if the border should be visible when
* the inner widget overflows
* @since 4.6
*/
void setOverflowBordersVisible(const bool visible);
/**
* Scroll the view until the given rectangle is visible
*
* @param rect rect we want visible, in coordinates mapped to the inner widget
* @since 4.4
*/
Q_INVOKABLE void ensureRectVisible(const QRectF &rect);
/**
* Scroll the view until the given item is visible
*
* @param item item we want visible
* @since 4.4
*/
Q_INVOKABLE void ensureItemVisible(QGraphicsItem *item);
/**
* The geometry of the viewport.
* @since 4.4
*/
QRectF viewportGeometry() const;
/**
* @return the size of the internal widget
* @since 4.4
*/
QSizeF contentsSize() const;
/**
* Sets the position of the internal widget relative to this widget
* @since 4.4
*/
void setScrollPosition(const QPointF &position);
/**
* @return the position of the internal widget relative to this widget
* @since 4.4
*/
QPointF scrollPosition() const;
/**
* Set the nap size of the kinetic scrolling:
* the scrolling will always stop at multiples of that size.
*
* @param the desired snap size
* @since 4.5
*/
void setSnapSize(const QSizeF &size);
/**
* @return the snap size of the kinetic scrolling
* @since 4.5
*/
QSizeF snapSize() const;
/**
* Sets the stylesheet used to control the visual display of this ScrollWidget
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet() const;
/**
* @return the native widget wrapped by this ScrollWidget
*/
QWidget *nativeWidget() const;
Q_SIGNALS:
/**
* The widget started or stopped an animated scroll
* @since 4.4
*/
void scrollStateChanged(QAbstractAnimation::State newState,
QAbstractAnimation::State oldState);
/**
* The viewport geomety changed, for instance due a widget resize
*
* @since 4.5
*/
void viewportGeometryChanged(const QRectF &geomety);
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void wheelEvent(QGraphicsSceneWheelEvent *event);
bool eventFilter(QObject *watched, QEvent *event);
void focusInEvent(QFocusEvent *event);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const;
bool sceneEventFilter(QGraphicsItem *i, QEvent *e);
private:
ScrollWidgetPrivate * const d;
Q_PRIVATE_SLOT(d, void verticalScroll(int value))
Q_PRIVATE_SLOT(d, void horizontalScroll(int value))
Q_PRIVATE_SLOT(d, void makeRectVisible())
Q_PRIVATE_SLOT(d, void makeItemVisible())
Q_PRIVATE_SLOT(d, void adjustScrollbars())
Q_PRIVATE_SLOT(d, void fixupX())
Q_PRIVATE_SLOT(d, void fixupY())
Q_PRIVATE_SLOT(d, void setScrollX())
Q_PRIVATE_SLOT(d, void setScrollY())
friend class ScrollWidgetPrivate;
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,101 +0,0 @@
/*
* Copyright 2009 by Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "separator.h"
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include "svg.h"
namespace Plasma
{
class SeparatorPrivate
{
public:
Svg *svg;
Qt::Orientation orientation;
};
Separator::Separator(QGraphicsItem *parent, Qt::WindowFlags wFlags)
: QGraphicsWidget(parent, wFlags),
d(new SeparatorPrivate())
{
d->svg = new Svg();
d->svg->setImagePath("widgets/line");
d->svg->setContainsMultipleImages(true);
setOrientation(Qt::Horizontal);
}
Separator::~Separator()
{
delete d->svg;
delete d;
}
void Separator::setOrientation(Qt::Orientation orientation)
{
d->orientation = orientation;
if (orientation == Qt::Horizontal) {
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
} else {
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
}
}
Qt::Orientation Separator::orientation()
{
return d->orientation;
}
void Separator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
if (d->svg){
if (d->orientation == Qt::Horizontal){
d->svg->paint(painter, boundingRect(), "horizontal-line");
} else {
d->svg->paint(painter, boundingRect(), "vertical-line");
}
}
}
QSizeF Separator::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
{
QSizeF hint = QGraphicsWidget::sizeHint(which, constraint);
if (d->orientation == Qt::Horizontal) {
hint.setHeight(d->svg->elementSize("horizontal-line").height());
} else {
hint.setWidth(d->svg->elementSize("vertical-line").width());
}
return hint;
}
} // Plasma namespace
#include "moc_separator.cpp"

View File

@ -1,60 +0,0 @@
/*
* Copyright 2009 by Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_SEPARATOR_H
#define PLASMA_SEPARATOR_H
#include <QGraphicsWidget>
#include <plasma/plasma_export.h>
#include <plasma/plasma.h>
namespace Plasma
{
class SeparatorPrivate;
/**
* @since 4.4
*/
class PLASMA_EXPORT Separator : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
public:
explicit Separator(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
virtual ~Separator();
void setOrientation(Qt::Orientation orientation);
Qt::Orientation orientation();
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const;
private:
SeparatorPrivate * const d;
};
} // Plasma namespace
#endif // multiple inclusion guard

File diff suppressed because it is too large Load Diff

View File

@ -1,455 +0,0 @@
/*
* KSysGuard, the KDE System Guard
*
* Copyright 1999 - 2001 Chris Schlaeger <cs@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_SIGNALPLOTTER_H
#define PLASMA_SIGNALPLOTTER_H
#include <QFont>
#include <QGraphicsWidget>
#include <plasma/plasma_export.h>
namespace Plasma
{
class SignalPlotterPrivate;
struct PlotColor
{
QColor color;
QColor darkColor;
};
/**
* @class SignalPlotter plasma/widgets/signalplotter.h <Plasma/Widgets/SignalPlotter>
*
* @short Provides a signal plotter for plasma.
*/
class PLASMA_EXPORT SignalPlotter : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(QString title READ title WRITE setTitle)
Q_PROPERTY(QString unit READ unit WRITE setUnit)
Q_PROPERTY(qreal scale READ scaledBy WRITE scale) // Note: The naming of the functions here is poor
Q_PROPERTY(bool useAutoRange READ useAutoRange WRITE setUseAutoRange)
Q_PROPERTY(uint horizontalScale READ horizontalScale WRITE setHorizontalScale)
Q_PROPERTY(bool showVerticalLines READ showVerticalLines WRITE setShowVerticalLines)
Q_PROPERTY(QColor verticalLinesColor READ verticalLinesColor WRITE setVerticalLinesColor)
Q_PROPERTY(uint verticalLinesDistance READ verticalLinesDistance WRITE setVerticalLinesDistance)
Q_PROPERTY(bool verticalLinesScroll READ verticalLinesScroll WRITE setVerticalLinesScroll)
Q_PROPERTY(bool showHorizontalLines READ showHorizontalLines WRITE setShowHorizontalLines)
Q_PROPERTY(QColor horizontalLinesColor READ horizontalLinesColor WRITE setHorizontalLinesColor)
Q_PROPERTY(QColor fontColor READ fontColor WRITE setFontColor)
Q_PROPERTY(QFont font READ font WRITE setFont)
Q_PROPERTY(uint horizontalLinesCount READ horizontalLinesCount WRITE setHorizontalLinesCount)
Q_PROPERTY(bool showLabels READ showLabels WRITE setShowLabels)
Q_PROPERTY(bool showTopBar READ showTopBar WRITE setShowTopBar)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
Q_PROPERTY(QString svgBackground READ svgBackground WRITE setSvgBackground)
Q_PROPERTY(bool thinFrame READ thinFrame WRITE setThinFrame)
Q_PROPERTY(bool stackPlots READ stackPlots WRITE setStackPlots)
public:
SignalPlotter(QGraphicsItem *parent = 0);
~SignalPlotter();
/**
* Add a new line to the graph plotter, with the specified color.
* Note that the order you add the plots must be the same order that
* the same data is given in (unless you reorder the plots).
* @param color the color to use for this plot
*/
Q_INVOKABLE void addPlot(const QColor &color);
/**
* Add data to the graph, and advance the graph by one time period.
* The data must be given as a list in the same order that the plots were
* added (or consequently reordered).
* @param samples a list with the new value for each plot
*/
Q_INVOKABLE void addSample(const QList<double> &samples);
/**
* Reorder the plots into the order given. For example:
* \code
* Plasma::SignalPlotter *s = new Plasma::SignalPlotter(parent);
* s->addPlot(Qt::Blue);
* s->addPlot(Qt::Green);
* QList neworder;
* neworder << 1 << 0;
* s->reorderPlots(newOrder);
* //Now the order is Green then Blue
* \endcode
* @param newOrder a list with the new position of each plot
*/
Q_INVOKABLE void reorderPlots(const QList<uint>& newOrder);
/**
* Removes the plot at the specified index.
* @param pos the index of the plot to be removed
*/
Q_INVOKABLE void removePlot(uint pos);
/**
* Return the list of plot colors, in the order that the plots
* were added (or later reordered).
* @return a list containing the color of every plot
*/
QList<PlotColor> &plotColors();
/**
* Set the title of the graph. Drawn in the top left.
* @param title the title to use in the plotter
*/
void setTitle(const QString &title);
/**
* Get the title of the graph. Drawn in the top left.
* @return the title to use in the plotter
*/
QString title() const;
/**
* Set the units. Drawn on the vertical axis of the graph.
* Must be already translated into the local language.
* @param unit the unit string to use
*/
void setUnit(const QString &unit);
/**
* Return the units used on the vertical axis of the graph.
* @return the unit string used
*/
QString unit() const;
/**
* Scale all the values down by the given amount. This is useful
* when the data is given in, say, kilobytes, but you set the
* units as megabytes. Thus you would have to call this with @p value
* set to 1024. This affects all the data already entered.
* @param delta the factor used to scale down the values
*/
void scale(qreal delta);
/**
* Amount scaled down by. @see scale
* @return the factor used to scale down the values
*/
qreal scaledBy() const;
/**
* Set the minimum and maximum values on the vertical axis
* automatically from the data available.
* @param value true if the plotter should calculate its own
* min and max values, otherwise false
*/
void setUseAutoRange(bool value);
/**
* Whether the vertical axis range is set automatically.
* @return true if the plotter calculates its own min and max
* values, otherwise false
*/
bool useAutoRange() const;
/**
* Change the minimum and maximum values drawn on the graph.
* Note that these values are sanitised. For example, if you
* set the minimum as 3, and the maximum as 97, then the graph
* would be drawn between 0 and 100. The algorithm to determine
* this "nice range" attempts to minimize the number of non-zero
* digits.
*
* Use setAutoRange instead to determine the range automatically
* from the data.
* @param min the minimum value to use for the vertical axis
* @param max the maximum value to use for the vertical axis
*/
void setVerticalRange(double min, double max);
/**
* Get the min value of the vertical axis. @see changeRange
* @return the minimum value to use for the vertical axis
*/
double verticalMinValue() const;
/**
* Get the max value of the vertical axis. @see changeRange
* @return the maximum value to use for the vertical axis
*/
double verticalMaxValue() const;
/**
* Set the number of pixels horizontally between data points
* @param scale the number of pixel to draw between two data points
*/
void setHorizontalScale(uint scale);
/**
* The number of pixels horizontally between data points
* @return the number of pixel drawn between two data points
*/
uint horizontalScale() const;
/**
* Whether to draw the vertical grid lines
* @param value true if the lines should be drawn, otherwise false
*/
void setShowVerticalLines(bool value);
/**
* Whether the vertical grid lines will be drawn
* @return true if the lines will be drawn, otherwise false
*/
bool showVerticalLines() const;
/**
* The color of the vertical grid lines
* @param color the color used to draw the vertical grid lines
*/
void setVerticalLinesColor(const QColor &color);
/**
* The color of the vertical grid lines
* @return the color used to draw the vertical grid lines
*/
QColor verticalLinesColor() const;
/**
* The horizontal distance between the vertical grid lines
* @param distance the distance between two vertical grid lines
*/
void setVerticalLinesDistance(uint distance);
/**
* The horizontal distance between the vertical grid lines
* @return the distance between two vertical grid lines
*/
uint verticalLinesDistance() const;
/**
* Whether the vertical lines move with the data
* @param value true if the vertical lines should move with the data
*/
void setVerticalLinesScroll(bool value);
/**
* Whether the vertical lines move with the data
* @return true if the vertical lines will move with the data
*/
bool verticalLinesScroll() const;
/**
* Whether to draw the horizontal grid lines
* @param value true if the lines should be drawn, otherwise false
*/
void setShowHorizontalLines(bool value);
/**
* Whether to draw the horizontal grid lines
* @return true if the lines will be drawn, otherwise false
*/
bool showHorizontalLines() const;
/**
* The color of the horizontal grid lines
* @param color the color used to draw the horizontal grid lines
*/
void setHorizontalLinesColor(const QColor &color);
/**
* The color of the horizontal grid lines
* @return the color used to draw the horizontal grid lines
*/
QColor horizontalLinesColor() const;
/**
* The color of the font used for the axis
* @param color the color used to draw the text of the vertical values
*/
void setFontColor(const QColor &color);
/**
* The color of the font used for the axis
* @return the color used to draw the text of the vertical values
*/
QColor fontColor() const;
/**
* The font used for the axis
* @param font the font used to draw the text of the vertical values
*/
void setFont(const QFont &font);
/**
* The font used for the axis
* @return the font used to draw the text of the vertical values
*/
QFont font() const;
/**
* The number of horizontal lines to draw. Doesn't include the top
* most and bottom most lines.
* @param count the number of horizontal lines to draw
*/
void setHorizontalLinesCount(uint count);
/**
* The number of horizontal lines to draw. Doesn't include the top
* most and bottom most lines.
* @return the number of horizontal lines that will be drawn
*/
uint horizontalLinesCount() const;
/**
* Whether to show the vertical axis labels
* @param value true if the values for the vertical axis should get drawn
*/
void setShowLabels(bool value);
/**
* Whether to show the vertical axis labels
* @return true if the values for the vertical axis will get drawn
*/
bool showLabels() const;
/**
* Whether to show the title etc at the top. Even if set, it
* won't be shown if there isn't room
* @param value true if the topbar should be shown
*/
void setShowTopBar(bool value);
/**
* Whether to show the title etc at the top. Even if set, it
* won't be shown if there isn't room
* @return true if the topbar will be shown
*/
bool showTopBar() const;
/**
* The color to set the background. This might not be seen
* if an svg is also set.
* @param color the color to use for the plotter background
*/
void setBackgroundColor(const QColor &color);
/**
* The color to set the background. This might not be seen
* if an svg is also set.
* @return the color of the plotter background
*/
QColor backgroundColor() const;
/**
* The filename of the svg background. Set to empty to disable
* again.
* @param filename the SVG file to use as a background image
*/
void setSvgBackground(const QString &filename);
/**
* The filename of the svg background. Set to empty to disable
* again.
* @return the file used as a background image
*/
QString svgBackground();
/**
* Return the last value that we have for plot i. Returns 0 if not known.
* @param i the plot we like to have the last value from
* @return the last value of this plot or 0 if not found
*/
double lastValue(uint i) const;
/**
* Return a translated string like: "34 %" or "100 KB" for plot i
* @param i the plot we like to have the value as string from
* @return the last value of this plot as a string
*/
QString lastValueAsString(uint i) const;
/**
* Whether to show a white line on the left and bottom of the widget,
* for a 3D effect
* @param set true if the frame should get drawn
*/
void setThinFrame(bool set);
/**
* show a white line on the left and bottom of the widget for a 3D effect
* @return true if frame show be draw
* @since 4.3
*/
bool thinFrame() const;
/**
* Whether to stack the plots on top of each other. The first plot
* added will be at the bottom. The next plot will be drawn on top,
* and so on.
* @param stack true if the plots should be stacked
*/
void setStackPlots(bool stack);
/**
* Whether to stack the plots. @see setStackPlots
* @return true if the plots will be stacked
*/
bool stackPlots() const;
/**
* Render the graph to the specified width and height, and return it
* as an image. This is useful, for example, if you draw a small version
* of the graph, but then want to show a large version in a tooltip etc
* @param width the width of the snapshot
* @param height the height of the snapshot
* @return a snapshot of the plotter as an image
*/
QPixmap getSnapshotImage(uint width, uint height);
/**
* Overwritten to be notified of size changes. Needed to update the
* data buffers that are used to store the samples.
*/
virtual void setGeometry(const QRectF &geometry);
protected:
void updateDataBuffers();
void calculateNiceRange();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void drawWidget(QPainter *p, uint w, uint height, int horizontalScale);
void drawBackground(QPainter *p, int w, int h);
void drawThinFrame(QPainter *p, int w, int h);
void drawTopBarFrame(QPainter *p, int separatorX, int height);
void drawTopBarContents(QPainter *p, int x, int width, int height);
void drawVerticalLines(QPainter *p, int top, int w, int h);
void drawPlots(QPainter *p, int top, int w, int h, int horizontalScale);
void drawAxisText(QPainter *p, int top, int h);
void drawHorizontalLines(QPainter *p, int top, int w, int h);
private:
SignalPlotterPrivate *const d;
Q_PRIVATE_SLOT(d, void themeChanged())
};
} // Plasma namespace
#endif

View File

@ -1,256 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "slider.h"
#include <QApplication>
#include <QPainter>
#include <QSlider>
#include <QStyleOptionSlider>
#include <QGraphicsSceneWheelEvent>
#include "theme.h"
#include "framesvg.h"
#include "graphicsview/private/style_p.h"
#include "graphicsview/private/focusindicator_p.h"
namespace Plasma
{
class SliderPrivate
{
public:
SliderPrivate()
{
}
~SliderPrivate()
{
}
Plasma::FrameSvg *background;
Plasma::Style::Ptr style;
FocusIndicator *focusIndicator;
};
Slider::Slider(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new SliderPrivate)
{
QSlider *native = new QSlider;
connect(native, SIGNAL(sliderMoved(int)), this, SIGNAL(sliderMoved(int)));
connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
setWidget(native);
native->setWindowIcon(QIcon());
native->setAttribute(Qt::WA_NoSystemBackground);
d->background = new Plasma::FrameSvg(this);
d->background->setImagePath("widgets/slider");
d->focusIndicator = new FocusIndicator(this, d->background);
d->style = Plasma::Style::sharedStyle();
native->setStyle(d->style.data());
}
Slider::~Slider()
{
delete d;
Plasma::Style::doneWithSharedStyle();
}
void Slider::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
if (!styleSheet().isNull() || Theme::defaultTheme()->useNativeWidgetStyle()) {
QGraphicsProxyWidget::paint(painter, option, widget);
return;
}
QSlider *slider = nativeWidget();
QStyle *style = slider->style();
QStyleOptionSlider sliderOpt;
sliderOpt.initFrom(slider);
//init the other stuff in the slider, taken from initStyleOption()
sliderOpt.subControls = QStyle::SC_None;
sliderOpt.activeSubControls = QStyle::SC_None;
sliderOpt.orientation = slider->orientation();
sliderOpt.maximum = slider->maximum();
sliderOpt.minimum = slider->minimum();
sliderOpt.tickPosition = (QSlider::TickPosition)slider->tickPosition();
sliderOpt.tickInterval = slider->tickInterval();
sliderOpt.upsideDown = (slider->orientation() == Qt::Horizontal) ?
(slider->invertedAppearance() != (sliderOpt.direction == Qt::RightToLeft))
: (!slider->invertedAppearance());
sliderOpt.direction = Qt::LeftToRight; // we use the upsideDown option instead
sliderOpt.sliderPosition = slider->sliderPosition();
sliderOpt.sliderValue = slider->value();
sliderOpt.singleStep = slider->singleStep();
sliderOpt.pageStep = slider->pageStep();
if (slider->orientation() == Qt::Horizontal) {
sliderOpt.state |= QStyle::State_Horizontal;
}
QRect backgroundRect =
style->subControlRect(QStyle::CC_Slider, &sliderOpt, QStyle::SC_SliderGroove, slider);
if (sliderOpt.orientation == Qt::Horizontal &&
d->background->hasElement("horizontal-background-center")) {
d->background->setElementPrefix("horizontal-background");
d->background->resizeFrame(backgroundRect.size());
d->background->paintFrame(painter, backgroundRect.topLeft());
} else if (sliderOpt.orientation == Qt::Vertical &&
d->background->hasElement("vertical-background-center")) {
d->background->setElementPrefix("vertical-background");
d->background->resizeFrame(backgroundRect.size());
d->background->paintFrame(painter, backgroundRect.topLeft());
} else if (sliderOpt.orientation == Qt::Horizontal) {
QRect elementRect = d->background->elementRect("horizontal-slider-line").toRect();
elementRect.setWidth(sliderOpt.rect.width());
elementRect.moveCenter(sliderOpt.rect.center());
d->background->paint(painter, elementRect, "horizontal-slider-line");
} else {
QRect elementRect = d->background->elementRect("vertical-slider-line").toRect();
elementRect.setHeight(sliderOpt.rect.height());
elementRect.moveCenter(sliderOpt.rect.center());
d->background->paint(painter, elementRect, "vertical-slider-line");
}
//Tickmarks
if (sliderOpt.tickPosition != QSlider::NoTicks) {
sliderOpt.subControls = QStyle::SC_SliderTickmarks;
sliderOpt.palette.setColor(
QPalette::WindowText, Plasma::Theme::defaultTheme()->color(Theme::TextColor));
style->drawComplexControl(QStyle::CC_Slider, &sliderOpt, painter, slider);
}
QRect handleRect = style->subControlRect(QStyle::CC_Slider, &sliderOpt, QStyle::SC_SliderHandle, slider);
QString handle;
if (sliderOpt.orientation == Qt::Horizontal) {
handle = "horizontal-slider-handle";
} else {
handle = "vertical-slider-handle";
}
QRect elementRect = d->background->elementRect(handle).toRect();
elementRect.moveCenter(handleRect.center());
if (elementRect.right() > rect().right()) {
elementRect.moveRight(rect().right());
}
if (elementRect.left() < rect().left()) {
elementRect.moveLeft(rect().left());
}
if (elementRect.top() < rect().top()) {
elementRect.moveTop(rect().top());
}
if (elementRect.bottom() > rect().bottom()) {
elementRect.moveBottom(rect().bottom());
}
if (orientation() == Qt::Vertical) {
d->focusIndicator->setCustomPrefix("vertical-slider-");
} else {
d->focusIndicator->setCustomPrefix("horizontal-slider-");
}
d->focusIndicator->setCustomGeometry(elementRect);
d->background->paint(painter, elementRect, handle);
}
void Slider::wheelEvent(QGraphicsSceneWheelEvent *event)
{
QWheelEvent e(event->pos().toPoint(), event->delta(),event->buttons(),event->modifiers(),event->orientation());
QApplication::sendEvent(widget(), &e);
event->accept();
}
void Slider::setMaximum(int max)
{
static_cast<QSlider*>(widget())->setMaximum(max);
}
int Slider::maximum() const
{
return static_cast<QSlider*>(widget())->maximum();
}
void Slider::setMinimum(int min)
{
static_cast<QSlider*>(widget())->setMinimum(min);
}
int Slider::minimum() const
{
return static_cast<QSlider*>(widget())->minimum();
}
void Slider::setRange(int min, int max)
{
static_cast<QSlider*>(widget())->setRange(min, max);
}
void Slider::setValue(int value)
{
static_cast<QSlider*>(widget())->setValue(value);
}
int Slider::value() const
{
return static_cast<QSlider*>(widget())->value();
}
void Slider::setOrientation(Qt::Orientation orientation)
{
static_cast<QSlider*>(widget())->setOrientation(orientation);
}
Qt::Orientation Slider::orientation() const
{
return static_cast<QSlider*>(widget())->orientation();
}
void Slider::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString Slider::styleSheet()
{
return widget()->styleSheet();
}
QSlider *Slider::nativeWidget() const
{
return static_cast<QSlider*>(widget());
}
} // namespace Plasma
#include "moc_slider.cpp"

View File

@ -1,147 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_SLIDER_H
#define PLASMA_SLIDER_H
#include <QGraphicsProxyWidget>
#include <plasma/plasma_export.h>
class QSlider;
namespace Plasma
{
class SliderPrivate;
/**
* @class Slider plasma/widgets/slider.h <Plasma/Widgets/Slider>
*
* @short Provides a plasma-themed QSlider.
*/
class PLASMA_EXPORT Slider : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(int maximum READ maximum WRITE setMaximum)
Q_PROPERTY(int minimum READ minimum WRITE setMinimum)
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(QSlider *nativeWidget READ nativeWidget)
public:
explicit Slider(QGraphicsWidget *parent = 0);
~Slider();
/**
* @return the maximum value
*/
int maximum() const;
/**
* @return the minimum value
*/
int minimum() const;
/**
* @return the current value
*/
int value() const;
/**
* @return the orientation of the slider
*/
Qt::Orientation orientation() const;
/**
* Sets the stylesheet used to control the visual display of this Slider
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* @return the native widget wrapped by this Slider
*/
QSlider *nativeWidget() const;
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void wheelEvent(QGraphicsSceneWheelEvent *event);
public Q_SLOTS:
/**
* Sets the maximum value the slider can take.
*/
void setMaximum(int maximum);
/**
* Sets the minimum value the slider can take.
*/
void setMinimum(int minimum);
/**
* Sets the minimum and maximum values the slider can take.
*/
void setRange(int minimum, int maximum);
/**
* Sets the value of the slider.
*
* If it is outside the range specified by minimum() and maximum(),
* it will be adjusted to fit.
*/
void setValue(int value);
/**
* Sets the orientation of the slider.
*/
void setOrientation(Qt::Orientation orientation);
Q_SIGNALS:
/**
* This signal is emitted when the user drags the slider.
*
* In fact, it is emitted whenever the sliderMoved(int) signal
* of QSlider would be emitted. See the Qt documentation for
* more information.
*/
void sliderMoved(int value);
/**
* This signal is emitted when the slider value has changed,
* with the new slider value as argument.
*/
void valueChanged(int value);
private:
SliderPrivate * const d;
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,233 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
* Copyright 2009 Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "spinbox.h"
#include <QPainter>
#include <QStyleOptionSpinBox>
#include <QGraphicsView>
#include <knuminput.h>
#include "applet.h"
#include "framesvg.h"
#include "graphicsview/private/focusindicator_p.h"
#include "graphicsview/private/style_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
class SpinBoxPrivate : public ThemedWidgetInterface<SpinBox>
{
public:
SpinBoxPrivate(SpinBox *spinBox)
: ThemedWidgetInterface<SpinBox>(spinBox),
focusIndicator(0)
{
buttonColorForText = true;
}
~SpinBoxPrivate()
{
}
Plasma::Style::Ptr style;
Plasma::FrameSvg *background;
FocusIndicator *focusIndicator;
};
SpinBox::SpinBox(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new SpinBoxPrivate(this))
{
KIntSpinBox *native = new KIntSpinBox;
connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
d->focusIndicator = new FocusIndicator(this, "widgets/lineedit");
d->setWidget(native);
native->setWindowIcon(QIcon());
native->setAttribute(Qt::WA_NoSystemBackground);
native->setAutoFillBackground(false);
d->background = new Plasma::FrameSvg(this);
d->background->setImagePath("widgets/lineedit");
d->background->setCacheAllRenderedFrames(true);
if (d->background->hasElement("hint-focus-over-base")) {
d->focusIndicator->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
}
d->style = Plasma::Style::sharedStyle();
native->setStyle(d->style.data());
d->initTheming();
QStyleOptionSpinBox spinOpt;
spinOpt.initFrom(nativeWidget());
QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
d->focusIndicator->setCustomGeometry(controlrect);
}
SpinBox::~SpinBox()
{
delete d;
Plasma::Style::doneWithSharedStyle();
}
void SpinBox::setMaximum(int max)
{
static_cast<KIntSpinBox*>(widget())->setMaximum(max);
}
int SpinBox::maximum() const
{
return static_cast<KIntSpinBox*>(widget())->maximum();
}
void SpinBox::setMinimum(int min)
{
static_cast<KIntSpinBox*>(widget())->setMinimum(min);
}
int SpinBox::minimum() const
{
return static_cast<KIntSpinBox*>(widget())->minimum();
}
void SpinBox::setRange(int min, int max)
{
static_cast<KIntSpinBox*>(widget())->setRange(min, max);
}
void SpinBox::setValue(int value)
{
static_cast<KIntSpinBox*>(widget())->setValue(value);
}
int SpinBox::value() const
{
return static_cast<KIntSpinBox*>(widget())->value();
}
void SpinBox::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString SpinBox::styleSheet()
{
return widget()->styleSheet();
}
KIntSpinBox *SpinBox::nativeWidget() const
{
return static_cast<KIntSpinBox*>(widget());
}
void SpinBox::changeEvent(QEvent *event)
{
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}
void SpinBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
update();
}
void SpinBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
update();
}
void SpinBox::resizeEvent(QGraphicsSceneResizeEvent *event)
{
QGraphicsProxyWidget::resizeEvent(event);
QStyleOptionSpinBox spinOpt;
spinOpt.initFrom(nativeWidget());
QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
if (d->focusIndicator) {
d->focusIndicator->setCustomGeometry(controlrect);
}
}
void SpinBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
QGraphicsProxyWidget::paint(painter, option, widget);
}
void SpinBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsWidget *widget = parentWidget();
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
while (!applet && widget) {
widget = widget->parentWidget();
applet = qobject_cast<Plasma::Applet *>(widget);
}
if (applet) {
applet->setStatus(Plasma::AcceptingInputStatus);
}
QGraphicsProxyWidget::mousePressEvent(event);
}
void SpinBox::focusOutEvent(QFocusEvent *event)
{
QGraphicsWidget *widget = parentWidget();
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
while (!applet && widget) {
widget = widget->parentWidget();
applet = qobject_cast<Plasma::Applet *>(widget);
}
if (applet) {
applet->setStatus(Plasma::UnknownStatus);
}
QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
if (qApp) {
if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
if (view->scene() && view->scene() == scene()) {
QApplication::sendEvent(view, &closeEvent);
}
}
}
QGraphicsProxyWidget::focusOutEvent(event);
}
} // namespace Plasma
#include "moc_spinbox.cpp"

View File

@ -1,150 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
* Copyright 2009 Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_SPINBOX_H
#define PLASMA_SPINBOX_H
#include <QGraphicsProxyWidget>
#include <plasma/plasma_export.h>
class KIntSpinBox;
namespace Plasma
{
class SpinBoxPrivate;
/**
* @class SpinBox plasma/widgets/slider.h <Plasma/Widgets/SpinBox>
*
* @short Provides a plasma-themed KIntSpinBox.
*/
class PLASMA_EXPORT SpinBox : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(int maximum READ maximum WRITE setMinimum)
Q_PROPERTY(int minimum READ minimum WRITE setMinimum)
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(KIntSpinBox *nativeWidget READ nativeWidget)
public:
explicit SpinBox(QGraphicsWidget *parent = 0);
~SpinBox();
/**
* @return the maximum value
*/
int maximum() const;
/**
* @return the minimum value
*/
int minimum() const;
/**
* @return the current value
*/
int value() const;
/**
* Sets the stylesheet used to control the visual display of this SpinBox
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* @return the native widget wrapped by this SpinBox
*/
KIntSpinBox *nativeWidget() const;
protected:
void changeEvent(QEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void resizeEvent(QGraphicsSceneResizeEvent *event);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void focusOutEvent(QFocusEvent *event);
public Q_SLOTS:
/**
* Sets the maximum value the slider can take.
*/
void setMaximum(int maximum);
/**
* Sets the minimum value the slider can take.
*/
void setMinimum(int minimum);
/**
* Sets the minimum and maximum values the slider can take.
*/
void setRange(int minimum, int maximum);
/**
* Sets the value of the slider.
*
* If it is outside the range specified by minimum() and maximum(),
* it will be adjusted to fit.
*/
void setValue(int value);
Q_SIGNALS:
/**
* This signal is emitted when the user drags the slider.
*
* In fact, it is emitted whenever the sliderMoved(int) signal
* of KIntSpinBox would be emitted. See the Qt documentation for
* more information.
*/
void sliderMoved(int value);
/**
* This signal is emitted when the slider value has changed,
* with the new slider value as argument.
*/
void valueChanged(int value);
/**
* This signal is emitted when editing is finished.
* This happens when the spinbox loses focus and when enter is pressed.
*/
void editingFinished();
private:
Q_PRIVATE_SLOT(d, void setPalette())
SpinBoxPrivate * const d;
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,144 +0,0 @@
/*
* Copyright 2008 by Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "svgwidget.h"
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include "kdebug.h"
#include "svg.h"
namespace Plasma
{
class SvgWidgetPrivate
{
public:
SvgWidgetPrivate(SvgWidget *widget, Svg *s, const QString &element)
: q(widget), svg(s), elementID(element)
{
}
void svgChanged()
{
q->update();
}
SvgWidget *q;
Svg *svg;
QString elementID;
};
SvgWidget::SvgWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags)
: QGraphicsWidget(parent, wFlags),
d(new SvgWidgetPrivate(this, 0, QString()))
{
}
SvgWidget::SvgWidget(Svg *svg, const QString &elementID, QGraphicsItem *parent, Qt::WindowFlags wFlags)
: QGraphicsWidget(parent, wFlags),
d(new SvgWidgetPrivate(this, svg, elementID))
{
}
SvgWidget::~SvgWidget()
{
delete d;
}
void SvgWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
// we check for receivers so that SvgWidgets that aren't being used for events remain "click
// transparent"
if (receivers(SIGNAL(clicked(Qt::MouseButton)))) {
event->accept();
} else {
QGraphicsWidget::mousePressEvent(event);
}
}
void SvgWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (boundingRect().contains(event->pos())) {
emit clicked(event->button());
}
}
void SvgWidget::setSvg(Svg *svg)
{
if (d->svg) {
disconnect(d->svg);
}
d->svg = svg;
if (svg) {
connect(svg, SIGNAL(repaintNeeded()), this, SLOT(svgChanged()));
}
update();
}
Svg *SvgWidget::svg() const
{
return d->svg;
}
void SvgWidget::setElementID(const QString &elementID)
{
if (d->svg) {
d->svg->setContainsMultipleImages(!elementID.isNull());
}
d->elementID = elementID;
update();
}
QString SvgWidget::elementID() const
{
return d->elementID;
}
void SvgWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
if (d->svg){
d->svg->paint(painter, boundingRect(), d->elementID);
}
}
QSizeF SvgWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
{
if (d->svg && which == Qt::PreferredSize) {
if (d->elementID.isNull()) {
return d->svg->size();
} else {
return d->svg->elementSize(d->elementID);
}
} else {
return QGraphicsWidget::sizeHint(which, constraint);
}
}
} // Plasma namespace
#include "moc_svgwidget.cpp"

View File

@ -1,76 +0,0 @@
/*
* Copyright 2008 by Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_SVGWIDGET_H
#define PLASMA_SVGWIDGET_H
#include <QGraphicsWidget>
#include <plasma/plasma_export.h>
#include <plasma/plasma.h>
namespace Plasma
{
class Svg;
class SvgWidgetPrivate;
}
Q_DECLARE_METATYPE(Plasma::Svg*)
namespace Plasma
{
class PLASMA_EXPORT SvgWidget : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(Plasma::Svg *svg READ svg WRITE setSvg)
Q_PROPERTY(QString elementID READ elementID WRITE setElementID)
public:
explicit SvgWidget(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
explicit SvgWidget(Svg *svg, const QString & elementID = QString(),
QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
virtual ~SvgWidget();
void setSvg(Svg *svg);
Svg *svg() const;
void setElementID(const QString &elementID);
QString elementID() const;
void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
Q_SIGNALS:
void clicked(Qt::MouseButton);
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const;
void mousePressEvent(QGraphicsSceneMouseEvent * event);
private:
Q_PRIVATE_SLOT(d, void svgChanged())
SvgWidgetPrivate * const d;
};
} // Plasma namespace
#endif // multiple inclusion guard

View File

@ -1,684 +0,0 @@
/*
* Copyright 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "tabbar.h"
#include <QGraphicsLinearLayout>
#include <QGraphicsLayoutItem>
#include <QGraphicsProxyWidget>
#include <QGraphicsScene>
#include <QGraphicsSceneWheelEvent>
#include <QIcon>
#include <QMenu>
#include <QPainter>
#include <QParallelAnimationGroup>
#include <QString>
#include <QStyleOption>
#include <kdebug.h>
#include "animator.h"
#include "animations/animation.h"
#include "graphicsview/private/nativetabbar_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
class TabBarProxy : public QGraphicsProxyWidget
{
public:
TabBarProxy(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent)
{
native = new NativeTabBar();
native->setAttribute(Qt::WA_NoSystemBackground);
setWidget(native);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
}
void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
//Don't paint the child widgets
static_cast<NativeTabBar *>(QGraphicsProxyWidget::widget())->render(
painter, QPoint(0, 0), QRegion(), 0);
}
NativeTabBar *native;
};
class TabBarPrivate : public ThemedWidgetInterface<TabBar>
{
public:
TabBarPrivate(TabBar *parent)
: ThemedWidgetInterface<TabBar>(parent),
tabProxy(0),
currentIndex(0),
tabWidgetMode(true),
oldPageAnimId(-1),
newPageAnimId(-1),
tabBarShown(true)
{
}
~TabBarPrivate()
{
}
void updateTabWidgetMode();
void slidingCompleted(QGraphicsItem *item);
void slidingNewPageCompleted();
void slidingOldPageCompleted();
void shapeChanged(const KTabBar::Shape shape);
TabBarProxy *tabProxy;
QList<QGraphicsWidget *> pages;
QGraphicsWidget *emptyTabBarSpacer;
QGraphicsLinearLayout *mainLayout;
QGraphicsLinearLayout *tabWidgetLayout;
QGraphicsLinearLayout *tabBarLayout;
int currentIndex;
bool tabWidgetMode;
QWeakPointer<QGraphicsWidget> oldPage;
QWeakPointer<QGraphicsWidget> newPage;
int oldPageAnimId;
int newPageAnimId;
Animation *oldPageAnim;
Animation *newPageAnim;
QParallelAnimationGroup *animGroup;
bool tabBarShown;
QWeakPointer<QGraphicsWidget> firstPositionWidget;
QWeakPointer<QGraphicsWidget> lastPositionWidget;
};
void TabBarPrivate::updateTabWidgetMode()
{
if (!tabBarShown) {
return;
}
bool tabWidget = false;
foreach (QGraphicsWidget *page, pages) {
if (page->preferredSize() != QSize(0, 0)) {
tabWidget = true;
break;
}
}
if (tabWidget != tabWidgetMode) {
if (tabWidget) {
mainLayout->removeAt(0);
tabBarLayout->insertItem(1, tabProxy);
mainLayout->addItem(tabWidgetLayout);
} else {
mainLayout->removeAt(0);
tabBarLayout->removeAt(1);
mainLayout->addItem(tabProxy);
}
}
//always show the tabbar
//FIXME: Qt BUG: calling show on a child of an hidden item it shows it anyways
//so we avoid to call it if the parent is hidden
if (!tabWidget && q->isVisible()) {
q->setTabBarShown(true);
}
tabWidgetMode = tabWidget;
if (!tabWidgetMode) {
q->setMinimumSize(QSize(0, 0));
q->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
} else {
tabProxy->native->setMinimumSize(QSize(0,0));
tabProxy->setMinimumSize(QSize(0,0));
}
}
void TabBarPrivate::slidingNewPageCompleted()
{
if (newPage) {
tabWidgetLayout->addItem(newPage.data());
}
newPageAnimId = -1;
mainLayout->invalidate();
emit q->currentChanged(currentIndex);
q->setFlags(0);
}
void TabBarPrivate::slidingOldPageCompleted()
{
QGraphicsWidget *item = oldPageAnim->targetWidget();
oldPageAnimId = -1;
if (item) {
item->hide();
}
q->setFlags(0);
}
void TabBarPrivate::shapeChanged(const QTabBar::Shape shape)
{
//FIXME: QGraphicsLinearLayout doesn't have setDirection, so for now
// North is equal to south and East is equal to West
switch (shape) {
case QTabBar::RoundedWest:
case QTabBar::TriangularWest:
case QTabBar::RoundedEast:
case QTabBar::TriangularEast:
q->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
tabBarLayout->setOrientation(Qt::Vertical);
tabWidgetLayout->setOrientation(Qt::Horizontal);
tabWidgetLayout->itemAt(0)->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
if (tabWidgetLayout->count() > 1) {
tabWidgetLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
}
tabProxy->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
break;
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
default:
q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
tabBarLayout->setOrientation(Qt::Horizontal);
tabWidgetLayout->setOrientation(Qt::Vertical);
tabWidgetLayout->itemAt(0)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
if (tabWidgetLayout->count() > 1) {
tabWidgetLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
}
tabProxy->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
}
tabProxy->setPreferredSize(tabProxy->native->sizeHint());
}
TabBar::TabBar(QGraphicsWidget *parent)
: QGraphicsWidget(parent),
d(new TabBarPrivate(this))
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
setContentsMargins(0,0,0,0);
d->tabProxy = new TabBarProxy(this);
d->tabWidgetLayout = new QGraphicsLinearLayout(Qt::Vertical);
d->tabBarLayout = new QGraphicsLinearLayout(Qt::Horizontal);
d->tabWidgetLayout->setContentsMargins(0,0,0,0);
d->mainLayout = new QGraphicsLinearLayout(Qt::Horizontal);
d->mainLayout->addItem(d->tabWidgetLayout);
setLayout(d->mainLayout);
d->mainLayout->setContentsMargins(0,0,0,0);
//simulate a page until there isn't one
//needed to make the widget resize well when there are no tab added
d->emptyTabBarSpacer = new QGraphicsWidget(this);
d->tabWidgetLayout->addItem(d->tabBarLayout);
d->tabWidgetLayout->addItem(d->emptyTabBarSpacer);
//tabBar is centered, so a stretch at begin one at the end
d->tabBarLayout->addStretch();
d->tabBarLayout->addItem(d->tabProxy);
d->tabBarLayout->addStretch();
d->tabBarLayout->setContentsMargins(0,0,0,0);
//d->tabBarLayout->setStretchFactor(d->tabProxy, 2);
d->newPageAnim = Animator::create(Animator::SlideAnimation);
d->oldPageAnim = Animator::create(Animator::SlideAnimation);
d->animGroup = new QParallelAnimationGroup(this);
d->animGroup->addAnimation(d->newPageAnim);
d->animGroup->addAnimation(d->oldPageAnim);
connect(d->tabProxy->native, SIGNAL(currentChanged(int)),
this, SLOT(setCurrentIndex(int)));
connect(d->tabProxy->native, SIGNAL(shapeChanged(QTabBar::Shape)),
this, SLOT(shapeChanged(QTabBar::Shape)));
connect(d->newPageAnim, SIGNAL(finished()), this, SLOT(slidingNewPageCompleted()));
connect(d->oldPageAnim, SIGNAL(finished()), this, SLOT(slidingOldPageCompleted()));
d->initTheming();
}
TabBar::~TabBar()
{
delete d;
}
int TabBar::insertTab(int index, const QIcon &icon, const QString &label,
QGraphicsLayoutItem *content)
{
QGraphicsWidget *page = new QGraphicsWidget(this);
page->setContentsMargins(0,0,0,0);
page->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
if (content) {
if (content->isLayout()) {
page->setLayout(static_cast<QGraphicsLayout *>(content));
} else {
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, page);
layout->setContentsMargins(0,0,0,0);
layout->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
layout->addItem(content);
page->setLayout(layout);
}
} else {
page->setPreferredSize(0, 0);
}
d->pages.insert(qBound(0, index, d->pages.count()), page);
if (d->pages.count() == 1) {
d->tabWidgetLayout->removeItem(d->emptyTabBarSpacer);
d->tabWidgetLayout->addItem(page);
page->setVisible(true);
page->setEnabled(true);
} else {
page->setVisible(false);
page->setEnabled(false);
}
d->tabProxy->setPreferredSize(d->tabProxy->native->sizeHint());
d->updateTabWidgetMode();
int actualIndex = d->tabProxy->native->insertTab(index, icon, label);
d->currentIndex = d->tabProxy->native->currentIndex();
d->tabProxy->setPreferredSize(d->tabProxy->native->sizeHint());
d->updateTabWidgetMode();
return actualIndex;
}
int TabBar::insertTab(int index, const QString &label, QGraphicsLayoutItem *content)
{
return insertTab(index, QIcon(), label, content);
}
int TabBar::addTab(const QIcon &icon, const QString &label, QGraphicsLayoutItem *content)
{
return insertTab(d->pages.count(), icon, label, content);
}
int TabBar::addTab(const QString &label, QGraphicsLayoutItem *content)
{
return insertTab(d->pages.count(), QIcon(), label, content);
}
int TabBar::currentIndex() const
{
return d->tabProxy->native->currentIndex();
}
void TabBar::resizeEvent(QGraphicsSceneResizeEvent * event)
{
if (!d->tabWidgetMode) {
d->tabProxy->setMinimumSize(event->newSize().toSize());
setMinimumSize(QSize(0, 0));
setMinimumHeight(d->tabProxy->widget()->minimumSizeHint().height());
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
} else {
setMinimumSize(QSize(-1, -1));
d->tabProxy->native->setMinimumSize(QSize(0,0));
}
}
void TabBar::setCurrentIndex(int index)
{
if (index >= d->pages.count() ||
d->pages.count() < 2 ||
d->currentIndex == index) {
return;
}
d->oldPage = d->pages.value(d->currentIndex);
if (d->oldPage) {
d->tabWidgetLayout->removeItem(d->oldPage.data());
}
if (index >= 0) {
d->newPage = d->pages.value(index);
}
setFlags(QGraphicsItem::ItemClipsChildrenToShape);
//if an animation was in rogress hide everything to avoid an inconsistent state
if (d->animGroup->state() != QAbstractAnimation::Stopped) {
foreach (QGraphicsWidget *page, d->pages) {
page->hide();
}
d->animGroup->stop();
}
if (d->newPage) {
d->newPage.data()->show();
d->newPage.data()->setEnabled(true);
}
if (d->oldPage) {
d->oldPage.data()->show();
d->oldPage.data()->setEnabled(false);
}
if (d->newPage && d->oldPage) {
//FIXME: it seems necessary to resiz the thing 2 times to have effect
d->newPage.data()->resize(1,1);
d->newPage.data()->resize(d->oldPage.data()->size());
QRect beforeCurrentGeom(d->oldPage.data()->geometry().toRect());
beforeCurrentGeom.moveTopRight(beforeCurrentGeom.topLeft());
if (index > d->currentIndex) {
d->newPage.data()->setPos(d->oldPage.data()->geometry().topRight());
d->newPageAnim->setProperty("movementDirection", Animation::MoveLeft);
d->newPageAnim->setProperty("distancePointF", QPointF(d->oldPage.data()->size().width(), 0));
d->newPageAnim->setTargetWidget(d->newPage.data());
d->oldPageAnim->setProperty("movementDirection", Animation::MoveLeft);
d->oldPageAnim->setProperty("distancePointF", QPointF(beforeCurrentGeom.width(), 0));
d->oldPageAnim->setTargetWidget(d->oldPage.data());
d->animGroup->start();
} else {
d->newPage.data()->setPos(beforeCurrentGeom.topLeft());
d->newPageAnim->setProperty("movementDirection", Animation::MoveRight);
d->newPageAnim->setProperty("distancePointF", QPointF(d->oldPage.data()->size().width(), 0));
d->newPageAnim->setTargetWidget(d->newPage.data());
d->oldPageAnim->setProperty("movementDirection", Animation::MoveRight);
d->oldPageAnim->setProperty("distancePointF",
QPointF(d->oldPage.data()->size().width(), 0));
d->oldPageAnim->setTargetWidget(d->oldPage.data());
d->animGroup->start();
}
} else if (d->newPage) {
d->tabWidgetLayout->addItem(d->newPage.data());
}
d->currentIndex = index;
d->tabProxy->native->setCurrentIndex(index);
}
int TabBar::count() const
{
return d->pages.count();
}
void TabBar::removeTab(int index)
{
if (index >= d->pages.count() || index < 0) {
return;
}
d->newPageAnim->stop();
d->oldPageAnim->stop();
int oldCurrentIndex = d->tabProxy->native->currentIndex();
d->tabProxy->native->removeTab(index);
d->currentIndex = oldCurrentIndex;
int currentIndex = d->tabProxy->native->currentIndex();
if (oldCurrentIndex == index) {
d->tabWidgetLayout->removeAt(1);
if (d->tabProxy->native->count() > 0) {
setCurrentIndex(currentIndex >= oldCurrentIndex ? currentIndex + 1 : currentIndex);
}
}
QGraphicsWidget *page = d->pages.takeAt(index);
scene()->removeItem(page);
page->deleteLater();
if (d->pages.count() > 0) {
d->updateTabWidgetMode();
} else {
d->tabWidgetLayout->addItem(d->emptyTabBarSpacer);
}
}
QGraphicsLayoutItem *TabBar::takeTab(int index)
{
if (index >= d->pages.count()) {
return 0;
}
int oldCurrentIndex = d->tabProxy->native->currentIndex();
d->tabProxy->native->removeTab(index);
int currentIndex = d->tabProxy->native->currentIndex();
if (oldCurrentIndex == index) {
d->tabWidgetLayout->removeAt(1);
if (d->tabProxy->native->count() > 0) {
setCurrentIndex(currentIndex >= oldCurrentIndex ? currentIndex + 1 : currentIndex);
}
}
QGraphicsWidget *page = d->pages.takeAt(index);
QGraphicsLayoutItem *returnItem = 0;
QGraphicsLayout *lay = page->layout();
if (lay && lay->count() == 1) {
returnItem = lay->itemAt(0);
lay->removeAt(0);
} else {
returnItem = lay;
}
if (returnItem) {
returnItem->setParentLayoutItem(0);
if (QGraphicsItem *item = returnItem->graphicsItem()) {
item->setParentItem(0);
}
}
page->setLayout(0);
scene()->removeItem(page);
page->deleteLater();
if (oldCurrentIndex != currentIndex) {
setCurrentIndex(currentIndex);
}
d->updateTabWidgetMode();
d->tabProxy->setPreferredSize(d->tabProxy->native->sizeHint());
return returnItem;
}
QGraphicsLayoutItem *TabBar::tabAt(int index)
{
if (index >= d->pages.count()) {
return 0;
}
QGraphicsWidget *page = d->pages.value(index);
QGraphicsLayoutItem *returnItem = 0;
QGraphicsLayout *lay = page->layout();
if (lay && lay->count() == 1) {
returnItem = lay->itemAt(0);
} else {
returnItem = lay;
}
return returnItem;
}
void TabBar::setTabText(int index, const QString &label)
{
if (index >= d->pages.count()) {
return;
}
d->tabProxy->native->setTabText(index, label);
}
QString TabBar::tabText(int index) const
{
return d->tabProxy->native->tabText(index);
}
void TabBar::setTabIcon(int index, const QIcon &icon)
{
d->tabProxy->native->setTabIcon(index, icon);
}
QIcon TabBar::tabIcon(int index) const
{
return d->tabProxy->native->tabIcon(index);
}
void TabBar::setTabBarShown(bool show)
{
if (!show && !d->tabWidgetMode) {
return;
}
if (d->tabBarShown == show) {
return;
}
d->tabBarShown = show;
if (!show) {
d->tabProxy->hide();
d->tabWidgetLayout->removeItem(d->tabBarLayout);
} else {
d->tabProxy->show();
d->tabWidgetLayout->insertItem(0, d->tabBarLayout);
}
}
bool TabBar::isTabBarShown() const
{
return d->tabBarShown;
}
void TabBar::setStyleSheet(const QString &stylesheet)
{
d->tabProxy->native->setStyleSheet(stylesheet);
}
QString TabBar::styleSheet() const
{
return d->tabProxy->native->styleSheet();
}
void TabBar::setTabHighlighted(int index, bool highlight)
{
d->tabProxy->native->setTabHighlighted(index, highlight);
}
bool TabBar::isTabHighlighted(int index) const
{
return d->tabProxy->native->isTabHighlighted(index);
}
KTabBar *TabBar::nativeWidget() const
{
return d->tabProxy->native;
}
void TabBar::wheelEvent(QGraphicsSceneWheelEvent * event)
{
Q_UNUSED(event)
//Still here for binary compatibility
}
void TabBar::changeEvent(QEvent *event)
{
d->changeEvent(event);
QGraphicsWidget::changeEvent(event);
}
void TabBar::setFirstPositionWidget(QGraphicsWidget *widget)
{
if (d->lastPositionWidget.data() == widget) {
return;
}
if (d->firstPositionWidget) {
QGraphicsWidget *widget = d->firstPositionWidget.data();
d->tabBarLayout->removeItem(widget);
scene()->removeItem(widget);
widget->deleteLater();
}
d->firstPositionWidget = widget;
if (widget) {
widget->setParentItem(this);
if (layoutDirection() == Qt::LeftToRight) {
d->tabBarLayout->insertItem(0, widget);
} else {
d->tabBarLayout->addItem(widget);
}
}
}
QGraphicsWidget *TabBar::firstPositionWidget() const
{
return d->firstPositionWidget.data();
}
void TabBar::setLastPositionWidget(QGraphicsWidget *widget)
{
if (d->lastPositionWidget.data() == widget) {
return;
}
if (d->lastPositionWidget) {
QGraphicsWidget *widget = d->lastPositionWidget.data();
d->tabBarLayout->removeItem(widget);
scene()->removeItem(widget);
widget->deleteLater();
}
d->lastPositionWidget = widget;
if (widget) {
widget->setParentItem(this);
if (layoutDirection() == Qt::LeftToRight) {
d->tabBarLayout->addItem(widget);
} else {
d->tabBarLayout->insertItem(0, widget);
}
}
}
QGraphicsWidget *TabBar::lastPositionWidget() const
{
return d->lastPositionWidget.data();
}
} // namespace Plasma
#include "moc_tabbar.cpp"

View File

@ -1,290 +0,0 @@
/*
* Copyright 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_TABBAR_H
#define PLASMA_TABBAR_H
#include <QGraphicsWidget>
#include <ktabbar.h>
#include <plasma/plasma_export.h>
class QString;
class QIcon;
namespace Plasma
{
class TabBarPrivate;
/**
* @class TabBar plasma/widgets/tabbar.h <Plasma/Widgets/TabBar>
*
* @short A tab bar widget, to be used for tabbed interfaces.
*
* Provides a Tab bar for use in a tabbed interface where each page is a QGraphicsLayoutItem.
* Only one of them is displayed at a given time. It is possible to add and remove tabs
* or modify their text label or their icon.
*/
class PLASMA_EXPORT TabBar : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(KTabBar *nativeWidget READ nativeWidget)
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
Q_PROPERTY(int count READ count)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(bool tabBarShown READ isTabBarShown WRITE setTabBarShown)
Q_PROPERTY(QGraphicsWidget *firstPositionWidget READ firstPositionWidget WRITE setFirstPositionWidget)
Q_PROPERTY(QGraphicsWidget *lastPositionWidget READ lastPositionWidget WRITE setLastPositionWidget)
public:
/**
* Constructs a new TabBar
*
* @param parent the parent of this widget
*/
explicit TabBar(QGraphicsWidget *parent = 0);
~TabBar();
/**
* Adds a new tab in the desired position
*
* @param index the position where to insert the new tab,
* if index <=0 will be the first position,
* if index >= count() will be the last
* @param icon the icon for this tab
* @param label the text label of the tab
* @param content the page content that will be shown by this tab
* @return the index of the inserted tab
*/
Q_INVOKABLE int insertTab(int index, const QIcon &icon, const QString &label,
QGraphicsLayoutItem *content = 0);
/**
* Adds a new tab in the desired position
* This is an overloaded member provided for convenience
* equivalent to insertTab(index, QIcon(), label);
*
* @param index the position where to insert the new tab,
* if index <=0 will be the first position,
* if index >= count() will be the last
* @param label the text label of the tab
* @param content the page content that will be shown by this tab
* @return the index of the inserted tab
*/
Q_INVOKABLE int insertTab(int index, const QString &label, QGraphicsLayoutItem *content = 0);
/**
* Adds a new tab in the last position
*
* @param icon the icon for this tab
* @param label the text label of the tab
* @param content the page content that will be shown by this tab
* @return the index of the inserted tab
*/
Q_INVOKABLE int addTab(const QIcon &icon, const QString &label, QGraphicsLayoutItem *content = 0);
/**
* Adds a new tab in the last position
* This is an overloaded member provided for convenience
* equivalent to addTab(QIcon(), label, page)
*
* @param label the text label of the tab
* @param content the page content that will be shown by this tab
* @return the index of the inserted tab
*/
Q_INVOKABLE int addTab(const QString &label, QGraphicsLayoutItem *content = 0);
/**
* Removes a tab, contents are deleted
*
* @param index the index of the tab to remove
*/
Q_INVOKABLE void removeTab(int index);
/**
* Removes a tab, the page is reparented to 0 and is returned
*
* @param index the index of the tab to remove
* @since 4.4
*/
Q_INVOKABLE QGraphicsLayoutItem *takeTab(int index);
/**
* Returns the contents of a page
*
* @param index the index of the tab to retrieve
* @since 4.4
*/
Q_INVOKABLE QGraphicsLayoutItem *tabAt(int index);
/**
* @return the index of the tab currently active
*/
int currentIndex() const;
/**
* @return the number of tabs in this tabbar
*/
int count() const;
/**
* Sets the text label of the given tab
*
* @param index the index of the tab to modify
* @param label the new text label of the given tab
*/
Q_INVOKABLE void setTabText(int index, const QString &label);
/**
* @return the text label of the given tab
*
* @param index the index of the tab we want to know its label
*/
Q_INVOKABLE QString tabText(int index) const;
/**
* Sets an icon for a given tab
*
* @param index the index of the tab to modify
* @param icon the new icon for the given tab
*/
Q_INVOKABLE void setTabIcon(int index, const QIcon &icon);
/**
* @return the current icon for a given tab
*
* @param index the index of the tab we want to know its icon
*/
Q_INVOKABLE QIcon tabIcon(int index) const;
/**
* shows or hides the tabbar, used if you just want to display the
* pages, when the tabbar doesn't have content pages at all this
* function has no effect
*
* @param show true if we want to show the tabbar
* @since 4.3
*/
void setTabBarShown(bool show);
/**
* @return true if the tabbar is shown
* @since 4.3
*/
bool isTabBarShown() const;
/**
* Sets the stylesheet used to control the visual display of this TabBar
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet() const;
/**
* Highlight the specified tab
* @param index of the tab to highlight
* @param highlight true if it should be highlighted, wrong if not
* @since 4.7
*/
Q_INVOKABLE void setTabHighlighted(int index, bool highlight);
/**
* @return if the tab at index is highlighted
* @since 4.7
*/
Q_INVOKABLE bool isTabHighlighted(int index) const;
/**
* @return the native widget wrapped by this TabBar
*/
KTabBar *nativeWidget() const;
/**
* Set a widget to be displayed on one side of the TabBar, depending on the
* LayoutDirection and the Shape.
* @param widget the widget to be displayed. Passing 0 will show nothing.
* Any previous widget will be deleted.
* @since 4.6
*/
void setFirstPositionWidget(QGraphicsWidget *widget);
/**
* @return the widget in the first position
* @since 4.6
*/
QGraphicsWidget *firstPositionWidget() const;
/**
* Set a widget to be displayed on one side of the TabBar, depending on the
* LayoutDirection and the Shape.
* @param widget the widget to be displayed. Passing 0 will show nothing.
* Any previous widget will be deleted.
* @since 4.6
*/
void setLastPositionWidget(QGraphicsWidget *widget);
/**
* @return the widget in the last position
* @since 4.6
*/
QGraphicsWidget *lastPositionWidget() const;
public Q_SLOTS:
/**
* Activate a given tab
*
* @param index the index of the tab to activate
*/
void setCurrentIndex(int index);
Q_SIGNALS:
/**
* Emitted when the active tab changes
*
* @param index the newly activated tab
*/
void currentChanged(int index);
protected:
void wheelEvent(QGraphicsSceneWheelEvent *event);
void resizeEvent(QGraphicsSceneResizeEvent * event);
void changeEvent(QEvent *event);
private:
TabBarPrivate * const d;
friend class TabBarPrivate;
Q_PRIVATE_SLOT(d, void slidingNewPageCompleted())
Q_PRIVATE_SLOT(d, void slidingOldPageCompleted())
Q_PRIVATE_SLOT(d, void shapeChanged(const QTabBar::Shape shape))
Q_PRIVATE_SLOT(d, void setPalette())
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,194 +0,0 @@
/*
* Copyright 2009 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "textbrowser.h"
#include <QGraphicsSceneWheelEvent>
#include <QMenu>
#include <QPainter>
#include <QScrollBar>
#include <ktextbrowser.h>
#include "svg.h"
#include "theme.h"
#include "graphicsview/private/style_p.h"
#include "private/themedwidgetinterface_p.h"
namespace Plasma
{
class TextBrowserPrivate : public ThemedWidgetInterface<TextBrowser>
{
public:
TextBrowserPrivate(TextBrowser *browser)
: ThemedWidgetInterface<TextBrowser>(browser),
savedMinimumHeight(0),
savedMaximumHeight(QWIDGETSIZE_MAX),
wasNotFixed(true)
{
}
void setFixedHeight()
{
KTextBrowser *native = q->nativeWidget();
if (native->document() &&
q->sizePolicy().verticalPolicy() == QSizePolicy::Fixed &&
native->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff) {
native->document()->setTextWidth(q->size().width());
QSize s = native->document()->size().toSize();
if (wasNotFixed) {
savedMinimumHeight = q->minimumHeight();
savedMaximumHeight = q->maximumHeight();
wasNotFixed = false;
}
q->setMinimumHeight(s.height());
q->setMaximumHeight(s.height());
} else if (!wasNotFixed) {
q->setMinimumHeight(savedMinimumHeight);
q->setMaximumHeight(savedMaximumHeight);
wasNotFixed = true;
}
}
KTextBrowser *native;
Plasma::Style::Ptr style;
int savedMinimumHeight;
int savedMaximumHeight;
bool wasNotFixed;
};
TextBrowser::TextBrowser(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new TextBrowserPrivate(this))
{
KTextBrowser *native = new KTextBrowser;
native->setWindowFlags(native->windowFlags()|Qt::BypassGraphicsProxyWidget);
connect(native, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
connect(native, SIGNAL(textChanged()), this, SLOT(setFixedHeight()));
native->setWindowIcon(QIcon());
d->setWidget(native);
d->native = native;
native->setAttribute(Qt::WA_NoSystemBackground);
native->setFrameShape(QFrame::NoFrame);
native->setTextBackgroundColor(Qt::transparent);
native->viewport()->setAutoFillBackground(false);
d->style = Plasma::Style::sharedStyle();
native->verticalScrollBar()->setStyle(d->style.data());
native->horizontalScrollBar()->setStyle(d->style.data());
d->initTheming();
}
TextBrowser::~TextBrowser()
{
delete d;
Plasma::Style::doneWithSharedStyle();
}
void TextBrowser::setText(const QString &text)
{
static_cast<KTextBrowser*>(widget())->setText(text);
}
QString TextBrowser::text() const
{
return static_cast<KTextBrowser*>(widget())->toHtml();
}
void TextBrowser::setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy)
{
nativeWidget()->setHorizontalScrollBarPolicy(policy);
}
void TextBrowser::setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy)
{
nativeWidget()->setVerticalScrollBarPolicy(policy);
}
void TextBrowser::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString TextBrowser::styleSheet()
{
return widget()->styleSheet();
}
KTextBrowser *TextBrowser::nativeWidget() const
{
return static_cast<KTextBrowser*>(widget());
}
void TextBrowser::append(const QString &text)
{
return nativeWidget()->append(text);
}
void TextBrowser::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
{
Q_UNUSED(sourceName)
KTextBrowser *te = nativeWidget();
te->clear();
foreach (const QVariant &v, data) {
if (v.canConvert(QVariant::String)) {
te->append(v.toString() + '\n');
}
}
}
void TextBrowser::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QMenu *popup = nativeWidget()->createStandardContextMenu(event->screenPos());
if (popup) {
popup->exec(event->screenPos());
delete popup;
}
}
void TextBrowser::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setFixedHeight();
QGraphicsProxyWidget::resizeEvent(event);
}
void TextBrowser::wheelEvent(QGraphicsSceneWheelEvent *event)
{
if (nativeWidget()->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff &&
nativeWidget()->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff) {
event->ignore();
} else {
QGraphicsProxyWidget::wheelEvent(event);
}
}
void TextBrowser::changeEvent(QEvent *event)
{
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include "moc_textbrowser.cpp"

View File

@ -1,121 +0,0 @@
/*
* Copyright 2009 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_TEXTBROWSER_H
#define PLASMA_TEXTBROWSER_H
#include <QGraphicsProxyWidget>
class KTextBrowser;
#include <plasma/plasma_export.h>
#include <plasma/dataengine.h>
namespace Plasma
{
class TextBrowserPrivate;
/**
* @class TextBrowser plasma/widgets/TextBrowser.h <Plasma/Widgets/TextBrowser>
*
* @short Provides a plasma-themed KTextBrowser.
*
* @since 4.3
*/
class PLASMA_EXPORT TextBrowser : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(KTextBrowser *nativeWidget READ nativeWidget)
public:
explicit TextBrowser(QGraphicsWidget *parent = 0);
~TextBrowser();
/**
* Sets the display text for this TextBrowser
*
* @param text the text to display; should be translated.
*/
void setText(const QString &text);
/**
* @return the display text
*/
QString text() const;
/**
* Sets the policy used to show/hide the horizontal scrollbar
*/
void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy);
/**
* Sets the policy used to show/hide the vertical scrollbar
*/
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy);
/**
* Sets the stylesheet used to control the visual display of this TextBrowser
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* @return the native widget wrapped by this TextBrowser
*/
KTextBrowser *nativeWidget() const;
public Q_SLOTS:
/**
* Allows appending text to the text browser
* @since 4.4
*/
void append(const QString &text);
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
Q_SIGNALS:
void textChanged();
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void wheelEvent(QGraphicsSceneWheelEvent *event);
void changeEvent(QEvent *event);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
private:
TextBrowserPrivate * const d;
Q_PRIVATE_SLOT(d, void setFixedHeight())
Q_PRIVATE_SLOT(d, void setPalette())
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,208 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "textedit.h"
#include <QGraphicsSceneContextMenuEvent>
#include <QMenu>
#include <QPainter>
#include <QScrollBar>
#include <QGraphicsView>
#include <ktextedit.h>
#include "applet.h"
#include "graphicsview/private/style_p.h"
#include "private/themedwidgetinterface_p.h"
#include "svg.h"
#include "theme.h"
namespace Plasma
{
class TextEditPrivate : public ThemedWidgetInterface<TextEdit>
{
public:
TextEditPrivate(TextEdit *textEdit)
: ThemedWidgetInterface<TextEdit>(textEdit)
{
}
~TextEditPrivate()
{
}
Plasma::Style::Ptr style;
};
TextEdit::TextEdit(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new TextEditPrivate(this))
{
setNativeWidget(new KTextEdit);
d->style = Plasma::Style::sharedStyle();
d->initTheming();
}
TextEdit::~TextEdit()
{
delete d;
Plasma::Style::doneWithSharedStyle();
}
void TextEdit::setText(const QString &text)
{
static_cast<KTextEdit*>(widget())->setText(text);
}
QString TextEdit::text() const
{
return static_cast<KTextEdit*>(widget())->toHtml();
}
void TextEdit::setReadOnly(bool readOnly)
{
static_cast<KTextEdit*>(widget())->setReadOnly(readOnly);
}
bool TextEdit::isReadOnly() const
{
return static_cast<KTextEdit*>(widget())->isReadOnly();
}
void TextEdit::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString TextEdit::styleSheet()
{
return widget()->styleSheet();
}
void TextEdit::setNativeWidget(KTextEdit *nativeWidget)
{
if (widget()) {
widget()->deleteLater();
}
nativeWidget->setWindowFlags(nativeWidget->windowFlags()|Qt::BypassGraphicsProxyWidget);
connect(nativeWidget, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
nativeWidget->setWindowIcon(QIcon());
d->setWidget(nativeWidget);
nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
nativeWidget->setFrameShape(QFrame::NoFrame);
nativeWidget->viewport()->setAutoFillBackground(false);
nativeWidget->verticalScrollBar()->setStyle(d->style.data());
nativeWidget->horizontalScrollBar()->setStyle(d->style.data());
}
KTextEdit *TextEdit::nativeWidget() const
{
return static_cast<KTextEdit*>(widget());
}
void TextEdit::append(const QString &text)
{
return nativeWidget()->append(text);
}
void TextEdit::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
{
Q_UNUSED(sourceName)
KTextEdit *te = nativeWidget();
te->clear();
foreach (const QVariant &v, data) {
if (v.canConvert(QVariant::String)) {
te->append(v.toString() + '\n');
}
}
}
void TextEdit::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QMenu *popup = nativeWidget()->mousePopupMenu();
popup->exec(event->screenPos());
delete popup;
}
void TextEdit::resizeEvent(QGraphicsSceneResizeEvent *event)
{
QGraphicsProxyWidget::resizeEvent(event);
}
void TextEdit::changeEvent(QEvent *event)
{
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}
void TextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsWidget *widget = parentWidget();
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
while (!applet && widget) {
widget = widget->parentWidget();
applet = qobject_cast<Plasma::Applet *>(widget);
}
if (applet) {
applet->setStatus(Plasma::AcceptingInputStatus);
}
QGraphicsProxyWidget::mousePressEvent(event);
}
void TextEdit::focusOutEvent(QFocusEvent *event)
{
QGraphicsWidget *widget = parentWidget();
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
while (!applet && widget) {
widget = widget->parentWidget();
applet = qobject_cast<Plasma::Applet *>(widget);
}
if (applet) {
applet->setStatus(Plasma::UnknownStatus);
}
QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
if (qApp) {
if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
if (view->scene() && view->scene() == scene()) {
QApplication::sendEvent(view, &closeEvent);
}
}
}
QGraphicsProxyWidget::focusOutEvent(event);
}
} // namespace Plasma
#include "moc_textedit.cpp"

View File

@ -1,129 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_TEXTEDIT_H
#define PLASMA_TEXTEDIT_H
#include <QGraphicsProxyWidget>
class KTextEdit;
#include <plasma/plasma_export.h>
#include <plasma/dataengine.h>
namespace Plasma
{
class TextEditPrivate;
/**
* @class TextEdit plasma/widgets/textedit.h <Plasma/Widgets/TextEdit>
*
* @short Provides a plasma-themed KTextEdit.
*/
class PLASMA_EXPORT TextEdit : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(KTextEdit *nativeWidget READ nativeWidget WRITE setNativeWidget)
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
public:
explicit TextEdit(QGraphicsWidget *parent = 0);
~TextEdit();
/**
* Sets the display text for this TextEdit
*
* @param text the text to display; should be translated.
*/
void setText(const QString &text);
/**
* @return the display text
*/
QString text() const;
/**
* Sets the text area to be read only or interactive
* @param true to make it read only, false for interactive
* @since 4.4
*/
void setReadOnly(bool readOnly);
/**
* @return true if the text area is non-interacive
*/
bool isReadOnly() const;
/**
* Sets the stylesheet used to control the visual display of this TextEdit
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* Sets the text edit wrapped by this TextEdit (widget must inherit KTextEdit), ownership is transferred to the TextEdit
*
* @param nativeWidget text edit that will be wrapped by this TextEdit
* @since KDE4.4
*/
void setNativeWidget(KTextEdit *nativeWidget);
/**
* @return the native widget wrapped by this TextEdit
*/
KTextEdit *nativeWidget() const;
public Q_SLOTS:
/**
* Allows appending text to the text browser
* @since 4.4
*/
void append(const QString &text);
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
Q_SIGNALS:
void textChanged();
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void focusOutEvent(QFocusEvent *event);
private:
TextEditPrivate * const d;
Q_PRIVATE_SLOT(d, void setPalette())
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,462 +0,0 @@
/*
* Copyright 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "toolbutton.h"
#include <QDir>
#include <QPainter>
#include <QPropertyAnimation>
#include <QStyleOptionGraphicsItem>
#include <QToolButton>
#include <kcolorutils.h>
#include <kiconeffect.h>
#include <qmimedatabase.h>
#include "animator.h"
#include "framesvg.h"
#include "paintutils.h"
#include "private/actionwidgetinterface_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
class ToolButtonPrivate : public ActionWidgetInterface<ToolButton>
{
public:
ToolButtonPrivate(ToolButton *toolButton)
: ActionWidgetInterface<ToolButton>(toolButton),
background(0),
svg(0),
underMouse(false)
{
}
~ToolButtonPrivate()
{
delete svg;
}
void setPixmap()
{
if (imagePath.isEmpty()) {
delete svg;
svg = 0;
return;
}
QMimeDatabase db;
QMimeType mime = db.mimeTypeForFile(absImagePath);
QPixmap pm;
if (mime.inherits("image/svg+xml") || mime.inherits("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != absImagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
if (!svgElement.isNull()) {
svg->setContainsMultipleImages(true);
}
}
//QPainter p(&pm);
if (!svgElement.isNull() && svg->hasElement(svgElement)) {
QSizeF elementSize = svg->elementSize(svgElement);
float scale = pm.width() / qMax(elementSize.width(), elementSize.height());
svg->resize(svg->size() * scale);
pm = svg->pixmap(svgElement);
} else {
svg->resize(pm.size());
pm = svg->pixmap();
}
} else {
delete svg;
svg = 0;
pm = QPixmap(absImagePath);
}
static_cast<QToolButton*>(q->widget())->setIcon(QIcon(pm));
}
void syncActiveRect();
void syncBorders();
void animationUpdate(qreal progress);
FrameSvg *background;
QPropertyAnimation *animation;
qreal opacity;
QRectF activeRect;
QString imagePath;
QString absImagePath;
Svg *svg;
QString svgElement;
bool underMouse;
};
void ToolButtonPrivate::syncActiveRect()
{
background->setElementPrefix("normal");
qreal left, top, right, bottom;
background->getMargins(left, top, right, bottom);
background->setElementPrefix("active");
qreal activeLeft, activeTop, activeRight, activeBottom;
background->getMargins(activeLeft, activeTop, activeRight, activeBottom);
activeRect = QRectF(QPointF(0, 0), q->size());
activeRect.adjust(left - activeLeft, top - activeTop,
-(right - activeRight), -(bottom - activeBottom));
background->setElementPrefix("normal");
}
void ToolButtonPrivate::syncBorders()
{
//set margins from the normal element
qreal left, top, right, bottom;
background->setElementPrefix("normal");
background->getMargins(left, top, right, bottom);
q->setContentsMargins(left, top, right, bottom);
//calc the rect for the over effect
syncActiveRect();
}
void ToolButtonPrivate::animationUpdate(qreal progress)
{
opacity = progress;
// explicit update
q->update();
}
ToolButton::ToolButton(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new ToolButtonPrivate(this))
{
d->background = new FrameSvg(this);
d->background->setImagePath("widgets/button");
d->background->setCacheAllRenderedFrames(true);
d->background->setElementPrefix("normal");
QToolButton *native = new QToolButton;
connect(native, SIGNAL(clicked()), this, SIGNAL(clicked()));
connect(native, SIGNAL(pressed()), this, SIGNAL(pressed()));
connect(native, SIGNAL(released()), this, SIGNAL(released()));
setWidget(native);
native->setWindowIcon(QIcon());
native->setAttribute(Qt::WA_NoSystemBackground);
native->setAutoRaise(true);
d->syncBorders();
setAcceptHoverEvents(true);
connect(d->background, SIGNAL(repaintNeeded()), SLOT(syncBorders()));
d->animation = new QPropertyAnimation(this, "animationUpdate");
d->animation->setStartValue(0);
d->animation->setEndValue(1);
d->initTheming();
}
ToolButton::~ToolButton()
{
delete d->animation;
delete d;
}
void ToolButton::setAnimationUpdate(qreal progress)
{
d->animationUpdate(progress);
}
qreal ToolButton::animationUpdate() const
{
return d->opacity;
}
void ToolButton::setAction(QAction *action)
{
d->setAction(action);
}
QAction *ToolButton::action() const
{
return d->action;
}
void ToolButton::setAutoRaise(bool raise)
{
nativeWidget()->setAutoRaise(raise);
}
bool ToolButton::autoRaise() const
{
return nativeWidget()->autoRaise();
}
void ToolButton::setText(const QString &text)
{
static_cast<QToolButton*>(widget())->setText(text);
updateGeometry();
}
QString ToolButton::text() const
{
return static_cast<QToolButton*>(widget())->text();
}
void ToolButton::setImage(const QString &path)
{
if (d->imagePath == path) {
return;
}
delete d->svg;
d->svg = 0;
d->imagePath = path;
bool absolutePath = !path.isEmpty() &&
#ifdef Q_OS_WIN
!QDir::isRelativePath(path)
#else
(path[0] == '/' || path.startsWith(QLatin1String(":/")))
#endif
;
if (absolutePath) {
d->absImagePath = path;
} else {
//TODO: package support
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap();
}
void ToolButton::setImage(const QString &path, const QString &elementid)
{
d->svgElement = elementid;
setImage(path);
}
void ToolButton::setIcon(const QIcon &icon)
{
nativeWidget()->setIcon(icon);
}
QIcon ToolButton::icon() const
{
return nativeWidget()->icon();
}
QString ToolButton::image() const
{
return d->imagePath;
}
void ToolButton::setDown(bool down)
{
nativeWidget()->setDown(down);
}
bool ToolButton::isDown() const
{
return nativeWidget()->isDown();
}
void ToolButton::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString ToolButton::styleSheet()
{
return widget()->styleSheet();
}
QToolButton *ToolButton::nativeWidget() const
{
return static_cast<QToolButton*>(widget());
}
void ToolButton::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap();
if (d->background) {
//resize all four panels
d->background->setElementPrefix("pressed");
d->background->resizeFrame(size());
d->background->setElementPrefix("focus");
d->background->resizeFrame(size());
d->syncActiveRect();
d->background->setElementPrefix("active");
d->background->resizeFrame(d->activeRect.size());
d->background->setElementPrefix("normal");
d->background->resizeFrame(size());
}
QGraphicsProxyWidget::resizeEvent(event);
}
void ToolButton::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
if (!styleSheet().isNull() || Theme::defaultTheme()->useNativeWidgetStyle()) {
QGraphicsProxyWidget::paint(painter, option, widget);
return;
}
QToolButton *button = nativeWidget();
QStyleOptionToolButton buttonOpt;
buttonOpt.initFrom(button);
buttonOpt.icon = button->icon();
buttonOpt.text = button->text();
buttonOpt.iconSize = button->iconSize();
buttonOpt.toolButtonStyle = button->toolButtonStyle();
bool animationState = (d->animation->state() == QAbstractAnimation::Running)? \
1:0;
if (button->isEnabled() && (animationState || !button->autoRaise() || d->underMouse || (buttonOpt.state & QStyle::State_On) || button->isChecked() || button->isDown())) {
if (button->isDown() || (buttonOpt.state & QStyle::State_On) || button->isChecked()) {
d->background->setElementPrefix("pressed");
} else {
d->background->setElementPrefix("normal");
}
d->background->resizeFrame(size());
if (animationState) {
QPixmap buffer = d->background->framePixmap();
QPainter bufferPainter(&buffer);
bufferPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
QColor alphaColor(Qt::black);
alphaColor.setAlphaF(qMin(qreal(0.95), d->opacity));
bufferPainter.fillRect(buffer.rect(), alphaColor);
bufferPainter.end();
painter->drawPixmap(QPoint(0,0), buffer);
buttonOpt.palette.setColor(QPalette::ButtonText, KColorUtils::mix(Plasma::Theme::defaultTheme()->color(Plasma::Theme::ButtonTextColor), Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor), 1-d->opacity));
} else {
d->background->paintFrame(painter);
buttonOpt.palette.setColor(QPalette::ButtonText, Plasma::Theme::defaultTheme()->color(Plasma::Theme::ButtonTextColor));
}
} else {
buttonOpt.palette.setColor(QPalette::ButtonText, Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
}
buttonOpt.font = font();
painter->setFont(buttonOpt.font);
button->style()->drawControl(QStyle::CE_ToolButtonLabel, &buttonOpt, painter, button);
}
void ToolButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
d->underMouse = true;
if (nativeWidget()->isDown() || !nativeWidget()->autoRaise()) {
return;
}
const int FadeInDuration = 75;
if (d->animation->state() != QAbstractAnimation::Stopped) {
d->animation->stop();
}
d->animation->setDuration(FadeInDuration);
d->animation->setDirection(QAbstractAnimation::Forward);
d->animation->start();
d->background->setElementPrefix("active");
QGraphicsProxyWidget::hoverEnterEvent(event);
}
void ToolButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
d->underMouse = false;
if (nativeWidget()->isDown() || !nativeWidget()->autoRaise()) {
return;
}
const int FadeOutDuration = 150;
if (d->animation->state() != QAbstractAnimation::Stopped) {
d->animation->stop();
}
d->animation->setDuration(FadeOutDuration);
d->animation->setDirection(QAbstractAnimation::Backward);
d->animation->start();
d->background->setElementPrefix("active");
QGraphicsProxyWidget::hoverLeaveEvent(event);
}
void ToolButton::changeEvent(QEvent *event)
{
d->changeEvent(event);
if (event->type() == QEvent::EnabledChange && !isEnabled()) {
d->underMouse = false;
}
QGraphicsProxyWidget::changeEvent(event);
}
QVariant ToolButton::itemChange(GraphicsItemChange change, const QVariant &value)
{
//If the widget is hidden while it's hovered and then we show it again
//we have to disable the hover otherwise it will remain hovered.
if (change == ItemVisibleHasChanged){
d->underMouse = false;
}
return QGraphicsProxyWidget::itemChange(change, value);
}
QSizeF ToolButton::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
{
QSizeF hint = QGraphicsProxyWidget::sizeHint(which, constraint);
return hint;
}
} // namespace Plasma
#include "moc_toolbutton.cpp"

View File

@ -1,206 +0,0 @@
/*
* Copyright 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_TOOLBUTTON_H
#define PLASMA_TOOLBUTTON_H
#include <QGraphicsProxyWidget>
class QToolButton;
#include <plasma/plasma_export.h>
namespace Plasma
{
class ToolButtonPrivate;
/**
* @class ToolButton plasma/widgets/pushbutton.h <Plasma/Widgets/ToolButton>
*
* @short Provides a plasma-themed QToolButton.
*/
class PLASMA_EXPORT ToolButton : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(bool autoRaise READ autoRaise WRITE setAutoRaise)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(QToolButton *nativeWidget READ nativeWidget)
Q_PROPERTY(QAction *action READ action WRITE setAction)
Q_PROPERTY(bool down READ isDown WRITE setDown)
Q_PROPERTY(qreal animationUpdate READ animationUpdate WRITE setAnimationUpdate)
public:
explicit ToolButton(QGraphicsWidget *parent = 0);
~ToolButton();
/**
* Sets if the toolbutton has an autoraise behaviour
*
* @param raise
*/
void setAutoRaise(bool raise);
/**
* @return true if the toolbutton has an autoraise behaviour
*/
bool autoRaise() const;
/**
* Sets the display text for this ToolButton
*
* @param text the text to display; should be translated.
*/
void setText(const QString &text);
/**
* @return the display text
*/
QString text() const;
/**
* Sets the path to an image to display.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
*/
void setImage(const QString &path);
/**
* Sets the path to an svg image to display and the id of the used svg element, if necessary.
*
* @param path the path to the image; if a relative path, then a themed image will be loaded.
* @param elementid the id of a svg element.
*
* @since 4.4
*/
void setImage(const QString &path, const QString &elementid);
/**
* @return the image path being displayed currently, or an empty string if none.
*/
QString image() const;
/**
* Sets the status of the button to pressed
*
* @param down
* @since 4.5
*/
void setDown(bool down);
/**
* @return true if the button is pressed down
* @since 4.4
*/
bool isDown() const;
/**
* Sets the stylesheet used to control the visual display of this ToolButton
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* Associate an action with this IconWidget
* this makes the button follow the state of the action, using its icon, text, etc.
* when the button is clicked, it will also trigger the action.
*
* @since 4.3
*/
void setAction(QAction *action);
/**
* @return the currently associated action, if any.
*
* @since 4.3
*/
QAction *action() const;
/**
* sets the icon for this toolbutton
*
* @param icon the icon we want to use
*
* @since 4.3
*/
void setIcon(const QIcon &icon);
/**
* @return the icon of this button
*
* @since 4.3
*/
QIcon icon() const;
/**
* @return the native widget wrapped by this ToolButton
*/
QToolButton *nativeWidget() const;
Q_SIGNALS:
void clicked();
/**
* @since 4.4
*/
void pressed();
/**
* @since 4.4
*/
void released();
protected:
void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget = 0);
void resizeEvent(QGraphicsSceneResizeEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void changeEvent(QEvent *event);
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const;
private Q_SLOTS:
void setAnimationUpdate(qreal progress);
qreal animationUpdate() const;
private:
Q_PRIVATE_SLOT(d, void syncBorders())
Q_PRIVATE_SLOT(d, void syncToAction())
Q_PRIVATE_SLOT(d, void clearAction())
Q_PRIVATE_SLOT(d, void setPixmap())
Q_PRIVATE_SLOT(d, void setPalette())
friend class ToolButtonPrivate;
ToolButtonPrivate *const d;
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,90 +0,0 @@
/*
* Copyright 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "treeview.h"
#include <QTreeView>
#include <QHeaderView>
#include <QScrollBar>
#include <kiconloader.h>
#include "graphicsview/private/style_p.h"
namespace Plasma
{
class TreeViewPrivate
{
public:
Plasma::Style::Ptr style;
};
TreeView::TreeView(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new TreeViewPrivate)
{
QTreeView *native = new QTreeView;
setWidget(native);
native->setWindowIcon(QIcon());
native->setAttribute(Qt::WA_NoSystemBackground);
native->setFrameStyle(QFrame::NoFrame);
d->style = Plasma::Style::sharedStyle();
native->verticalScrollBar()->setStyle(d->style.data());
native->horizontalScrollBar()->setStyle(d->style.data());
}
TreeView::~TreeView()
{
delete d;
Plasma::Style::doneWithSharedStyle();
}
void TreeView::setModel(QAbstractItemModel *model)
{
nativeWidget()->setModel(model);
}
QAbstractItemModel *TreeView::model()
{
return nativeWidget()->model();
}
void TreeView::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString TreeView::styleSheet()
{
return widget()->styleSheet();
}
QTreeView *TreeView::nativeWidget() const
{
return static_cast<QTreeView*>(widget());
}
}
#include "moc_treeview.cpp"

View File

@ -1,87 +0,0 @@
/*
* Copyright 2008 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_TREEVIEW_H
#define PLASMA_TREEVIEW_H
#include <QGraphicsProxyWidget>
#include <plasma/plasma_export.h>
class QTreeView;
class QAbstractItemModel;
namespace Plasma
{
class TreeViewPrivate;
/**
* @class TreeView plasma/widgets/treeview.h <Plasma/Widgets/TreeView>
*
* @short Provides a plasma-themed QTreeView.
*/
class PLASMA_EXPORT TreeView : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel)
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(QTreeView *nativeWidget READ nativeWidget)
public:
explicit TreeView(QGraphicsWidget *parent = 0);
~TreeView();
/**
* Sets a model for this weather view
*
* @param model the model to display
*/
void setModel(QAbstractItemModel *model);
/**
* @return the model shown by this view
*/
QAbstractItemModel *model();
/**
* Sets the stylesheet used to control the visual display of this TreeView
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* @return the native widget wrapped by this TreeView
*/
QTreeView *nativeWidget() const;
private:
TreeViewPrivate *const d;
};
}
#endif // multiple inclusion guard

View File

@ -1,640 +0,0 @@
/*
* Copyright 2009 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "videowidget.h"
#include "config-plasma.h"
#include <QUrl>
#include <QTimer>
#include <QGraphicsLinearLayout>
#include <QGraphicsSceneResizeEvent>
#include <kiconloader.h>
#if !PLASMA_NO_KIO
#include <kfiledialog.h>
#else
#include <QFileDialog>
#endif
#include <phonon/videowidget.h>
#include <phonon/mediaobject.h>
#include <phonon/mediasource.h>
#include <phonon/audiooutput.h>
#include <plasma/animations/animation.h>
#include <plasma/widgets/iconwidget.h>
#include <plasma/widgets/slider.h>
#include <plasma/widgets/frame.h>
namespace Plasma
{
class VideoWidgetPrivate
{
public:
VideoWidgetPrivate(VideoWidget *video)
: q(video),
ticking(false),
forceControlsVisible(false),
animation(0),
hideTimer(0),
shownControls(VideoWidget::NoControls),
controlsWidget(0),
previousButton(0),
playButton(0),
pauseButton(0),
stopButton(0),
playPauseButton(0),
nextButton(0),
progress(0),
volume(0),
openFileButton(0)
{
}
~VideoWidgetPrivate()
{
}
void playPause();
void ticked(qint64 progress);
void totalTimeChanged(qint64 time);
void setPosition(int newProgress);
void setVolume(int value);
void volumeChanged(qreal value);
void showOpenFileDialog();
void openFile(const QString &path);
void stateChanged(Phonon::State newState, Phonon::State oldState);
void animateControlWidget(bool show);
void hideControlWidget();
void slidingCompleted();
bool spaceForControlsAvailable();
VideoWidget *q;
Phonon::VideoWidget *videoWidget;
Phonon::AudioOutput *audioOutput;
Phonon::MediaObject *media;
bool ticking;
bool forceControlsVisible;
//control widgets
Plasma::Animation *animation;
QTimer *hideTimer;
VideoWidget::Controls shownControls;
Plasma::Frame *controlsWidget;
IconWidget *previousButton;
IconWidget *playButton;
IconWidget *pauseButton;
IconWidget *stopButton;
IconWidget *playPauseButton;
IconWidget *nextButton;
Slider *progress;
Slider *volume;
IconWidget *openFileButton;
};
void VideoWidgetPrivate::playPause()
{
if (media->state() == Phonon::PlayingState) {
media->pause();
} else {
media->play();
}
}
void VideoWidgetPrivate::ticked(qint64 newProgress)
{
ticking = true;
progress->setValue(newProgress);
ticking = false;
}
void VideoWidgetPrivate::totalTimeChanged(qint64 time)
{
ticking = true;
//FIXME: this will break for veeery long stuff, butPhonon::SeekSlider seems to have the same problem
progress->setRange(0, time);
ticking = false;
}
void VideoWidgetPrivate::setPosition(int progress)
{
if (!ticking) {
media->seek(progress);
}
}
void VideoWidgetPrivate::setVolume(int value)
{
audioOutput->setVolume(qreal(value)/100.0);
}
void VideoWidgetPrivate::volumeChanged(qreal value)
{
volume->setValue(value*100);
}
void VideoWidgetPrivate::showOpenFileDialog()
{
#if !PLASMA_NO_KIO
openFile(KFileDialog::getOpenFileName());
#else
openFile(QFileDialog::getOpenFileName());
#endif
}
void VideoWidgetPrivate::openFile(const QString &path)
{
media->setCurrentSource(Phonon::MediaSource(path));
media->play();
}
void VideoWidgetPrivate::stateChanged(Phonon::State newState, Phonon::State oldState)
{
Q_UNUSED(oldState)
if (playPauseButton) {
if (newState == Phonon::PlayingState) {
playPauseButton->setIcon("media-playback-pause");
} else {
playPauseButton->setIcon("media-playback-start");
}
}
}
void VideoWidgetPrivate::animateControlWidget(bool show)
{
if (!controlsWidget || controlsWidget->isVisible() == show) {
return;
}
const int distance = controlsWidget->size().height();
if (!controlsWidget->isVisible()) {
controlsWidget->setPos(0, -distance);
controlsWidget->show();
}
//clip only when animating
q->setFlags(q->flags()|QGraphicsItem::ItemClipsChildrenToShape);
if (!animation) {
animation = Plasma::Animator::create(Plasma::Animator::SlideAnimation, q);
animation->setTargetWidget(controlsWidget);
animation->setProperty("movementDirection", Animation::MoveDown);
q->connect(animation, SIGNAL(finished()), q, SLOT(slidingCompleted()));
}
animation->setProperty("distance", distance);
animation->setProperty("direction", show? QAbstractAnimation::Forward : QAbstractAnimation::Backward);
animation->start();
}
void VideoWidgetPrivate::hideControlWidget()
{
animateControlWidget(false);
}
void VideoWidgetPrivate::slidingCompleted()
{
if (!controlsWidget) {
return;
}
//usually don't clip
q->setFlags(q->flags()^QGraphicsItem::ItemClipsChildrenToShape);
if (controlsWidget->pos().y() < 0) {
controlsWidget->hide();
} else if (!forceControlsVisible) {
hideTimer->start(3000);
}
}
bool VideoWidgetPrivate::spaceForControlsAvailable()
{
if (controlsWidget) {
QSize hint = controlsWidget->effectiveSizeHint(Qt::MinimumSize).toSize();
return (q->size().width() >= hint.width()) &&
(q->size().height() >= hint.height());
} else {
return true;
}
}
VideoWidget::VideoWidget(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new VideoWidgetPrivate(this))
{
d->videoWidget = new Phonon::VideoWidget;
d->audioOutput = new Phonon::AudioOutput(this);
d->media = new Phonon::MediaObject(this);
//it appears that the path has to be created BEFORE setting the proxy
Phonon::createPath(d->media, d->videoWidget);
Phonon::createPath(d->media, d->audioOutput);
setWidget(d->videoWidget);
d->videoWidget->setWindowIcon(QIcon());
setAcceptHoverEvents(true);
connect(d->media, SIGNAL(tick(qint64)), this, SIGNAL(tick(qint64)));
connect(d->media, SIGNAL(aboutToFinish()), this, SIGNAL(aboutToFinish()));
}
VideoWidget::~VideoWidget()
{
delete d;
}
Phonon::MediaObject *VideoWidget::mediaObject() const
{
return d->media;
}
Phonon::AudioOutput *VideoWidget::audioOutput() const
{
return d->audioOutput;
}
void VideoWidget::setUrl(const QString &url)
{
QString fileUrl;
if (url.startsWith('/')) {
fileUrl = "file://" % url;
} else {
fileUrl = url;
}
if (fileUrl == d->media->currentSource().url().toString()) {
return;
}
d->media->setCurrentSource(Phonon::MediaSource(fileUrl));
}
QString VideoWidget::url() const
{
return d->media->currentSource().url().toString();
}
void VideoWidget::setUsedControls(const Controls controls)
{
if (controls == d->shownControls) {
return;
}
d->shownControls = controls;
//kDebug()<<"Setting used controls"<<controls;
QGraphicsLinearLayout *controlsLayout = 0;
if (controls != NoControls && d->controlsWidget == 0) {
d->controlsWidget = new Plasma::Frame(this);
d->controlsWidget->setFrameShadow(Plasma::Frame::Raised);
controlsLayout = new QGraphicsLinearLayout(Qt::Horizontal, d->controlsWidget);
d->hideTimer = new QTimer(this);
connect(d->hideTimer, SIGNAL(timeout()), this, SLOT(hideControlWidget()));
//controls == NoControls
} else if (d->controlsWidget != 0) {
d->controlsWidget->deleteLater();
d->hideTimer->deleteLater();
d->controlsWidget = 0;
//disconnect all the stuff that wasn't automatically disconnected 'cause widget deaths
disconnect(d->media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(stateChanged(Phonon::State,Phonon::State)));
disconnect(d->media, SIGNAL(tick(qint64)), this, SLOT(ticked(qint64)));
disconnect(d->media, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64)));
disconnect(d->audioOutput, SIGNAL(volumeChanged(qreal)), this, SLOT(volumeChanged(qreal)));
return;
}
Q_ASSERT(controlsLayout);
//empty the layout
while (controlsLayout->count() > 0) {
controlsLayout->removeAt(0);
}
if (controls&Previous) {
if (!d->previousButton) {
d->previousButton = new IconWidget(d->controlsWidget);
d->previousButton->setIcon("media-playback-start");
connect(d->playButton, SIGNAL(clicked()), this, SLOT(PreviousRequested()));
}
controlsLayout->addItem(d->previousButton);
} else {
d->previousButton->deleteLater();
d->previousButton = 0;
}
if (controls&Play) {
if (!d->playButton) {
d->playButton = new IconWidget(d->controlsWidget);
d->playButton->setIcon("media-playback-start");
connect(d->playButton, SIGNAL(clicked()), this, SLOT(play()));
}
controlsLayout->addItem(d->playButton);
} else {
d->playButton->deleteLater();
d->playButton = 0;
}
if (controls&Pause) {
if (!d->pauseButton) {
d->pauseButton = new IconWidget(d->controlsWidget);
d->pauseButton->setIcon("media-playback-pause");
connect(d->pauseButton, SIGNAL(clicked()), this, SLOT(pause()));
}
controlsLayout->addItem(d->pauseButton);
} else {
d->pauseButton->deleteLater();
d->pauseButton = 0;
}
if (controls&Stop) {
if (!d->stopButton) {
d->stopButton = new IconWidget(d->controlsWidget);
d->stopButton->setIcon("media-playback-stop");
connect(d->stopButton, SIGNAL(clicked()), this, SLOT(stop()));
}
controlsLayout->addItem(d->stopButton);
} else {
d->stopButton->deleteLater();
d->stopButton = 0;
}
if (controls&PlayPause) {
if (!d->playPauseButton) {
d->playPauseButton = new IconWidget(d->controlsWidget);
d->playPauseButton->setIcon("media-playback-start");
connect(d->playPauseButton, SIGNAL(clicked()), this, SLOT(playPause()));
}
controlsLayout->addItem(d->playPauseButton);
} else {
d->playPauseButton->deleteLater();
d->playPauseButton = 0;
}
if (controls&Next) {
if (!d->nextButton) {
d->nextButton = new IconWidget(d->nextButton);
d->nextButton->setIcon("media-playback-start");
connect(d->nextButton, SIGNAL(clicked()), this, SIGNAL(nextRequested()));
}
controlsLayout->addItem(d->nextButton);
} else {
d->nextButton->deleteLater();
d->nextButton = 0;
}
connect(d->media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(stateChanged(Phonon::State,Phonon::State)));
if (controls&Progress) {
if (!d->progress) {
d->progress = new Slider(d->controlsWidget);
d->progress->setMinimum(0);
d->progress->setMaximum(100);
d->progress->setOrientation(Qt::Horizontal);
controlsLayout->setStretchFactor(d->progress, 4);
d->progress->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
connect(d->media, SIGNAL(tick(qint64)), this, SLOT(ticked(qint64)));
connect(d->media, SIGNAL(totalTimeChanged(qint64)), SLOT(totalTimeChanged(qint64)));
connect(d->progress, SIGNAL(valueChanged(int)), this, SLOT(setPosition(int)));
}
controlsLayout->addItem(d->progress);
} else {
d->progress->deleteLater();
d->progress = 0;
}
if (controls&Volume) {
if (!d->volume) {
d->volume = new Slider(d->controlsWidget);
d->volume->setMinimum(0);
d->volume->setMaximum(100);
d->volume->setValue(100);
d->volume->setOrientation(Qt::Horizontal);
d->volume->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
connect(d->volume, SIGNAL(valueChanged(int)), SLOT(setVolume(int)));
connect(d->audioOutput, SIGNAL(volumeChanged(qreal)), SLOT(volumeChanged(qreal)));
}
controlsLayout->addItem(d->volume);
} else {
d->volume->deleteLater();
d->volume = 0;
}
if (controls&OpenFile) {
if (!d->openFileButton) {
d->openFileButton = new IconWidget(d->controlsWidget);
d->openFileButton->setIcon(KDE::icon("document-open"));
connect(d->openFileButton, SIGNAL(clicked()), this, SLOT(showOpenFileDialog()));
}
controlsLayout->addItem(d->openFileButton);
} else {
d->openFileButton->deleteLater();
d->openFileButton = 0;
}
controlsLayout->activate();
d->controlsWidget->setPos(0,-d->controlsWidget->size().height());
d->controlsWidget->resize(size().width(), d->controlsWidget->size().height());
d->controlsWidget->hide();
}
VideoWidget::Controls VideoWidget::usedControls() const
{
return d->shownControls;
}
void VideoWidget::play()
{
if (d->media->state() == Phonon::PlayingState) {
return;
}
d->media->play();
}
void VideoWidget::pause()
{
if (d->media->state() == Phonon::PausedState) {
return;
}
d->media->pause();
}
void VideoWidget::stop()
{
if (d->media->state() == Phonon::StoppedState) {
return;
}
d->media->stop();
}
void VideoWidget::seek(qint64 time)
{
if (d->media->currentTime() == time) {
return;
}
d->media->seek(time);
}
qint64 VideoWidget::currentTime() const
{
return d->media->currentTime();
}
qint64 VideoWidget::totalTime() const
{
return d->media->totalTime();
}
qint64 VideoWidget::remainingTime() const
{
return d->media->remainingTime();
}
void VideoWidget::setControlsVisible(bool visible)
{
if (d->controlsWidget) {
d->forceControlsVisible = visible;
d->animateControlWidget(visible);
}
}
bool VideoWidget::controlsVisible() const
{
return d->controlsWidget != 0 && d->controlsWidget->isVisible();
}
void VideoWidget::setTickInterval(qint64 interval)
{
d->media->setTickInterval(interval);
}
qint64 VideoWidget::tickInterval() const
{
return d->media->tickInterval();
}
void VideoWidget::setStyleSheet(const QString &stylesheet)
{
d->videoWidget->setStyleSheet(stylesheet);
}
QString VideoWidget::styleSheet()
{
return d->videoWidget->styleSheet();
}
Phonon::VideoWidget *VideoWidget::nativeWidget() const
{
return d->videoWidget;
}
void VideoWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
{
QGraphicsProxyWidget::resizeEvent(event);
if (d->controlsWidget) {
QSize newControlsSize(event->newSize().width(), d->controlsWidget->size().height());
int newHeight = event->newSize().height();
qreal leftMargin, topMargin, rightMargin, bottomMargin;
d->controlsWidget->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
if (newHeight/5 >= KIconLoader::SizeEnormous) {
newControlsSize.setHeight(KIconLoader::SizeEnormous+topMargin+bottomMargin);
} else if (newHeight/5 >= KIconLoader::SizeHuge) {
newControlsSize.setHeight(KIconLoader::SizeHuge+topMargin+bottomMargin);
} else if (newHeight/5 >= KIconLoader::SizeLarge) {
newControlsSize.setHeight(KIconLoader::SizeLarge+topMargin+bottomMargin);
} else if (newHeight/5 >= KIconLoader::SizeMedium) {
newControlsSize.setHeight(KIconLoader::SizeMedium+topMargin+bottomMargin);
} else {
newControlsSize.setHeight(KIconLoader::SizeSmallMedium+topMargin+bottomMargin);
}
d->controlsWidget->resize(newControlsSize);
if (d->spaceForControlsAvailable()) {
d->animateControlWidget(false);
}
}
}
void VideoWidget::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
if (d->controlsWidget &&
!d->forceControlsVisible &&
d->spaceForControlsAvailable()) {
d->animateControlWidget(true);
}
}
void VideoWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
if (d->controlsWidget && !d->forceControlsVisible) {
d->hideTimer->start(1000);
}
}
void VideoWidget::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
if (d->forceControlsVisible || !d->controlsWidget) {
return;
}
d->hideTimer->start(3000);
if (!d->controlsWidget->isVisible() &&
d->spaceForControlsAvailable()) {
d->animateControlWidget(true);
}
}
} // namespace Plasma
#include "moc_videowidget.cpp"

View File

@ -1,246 +0,0 @@
/*
* Copyright 2009 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_VIDEOWIDGET_H
#define PLASMA_VIDEOWIDGET_H
#include <QGraphicsProxyWidget>
#include <plasma/plasma_export.h>
namespace Phonon {
class VideoWidget;
class MediaObject;
class AudioOutput;
}
class KUrl;
namespace Plasma
{
class VideoWidgetPrivate;
/**
* @class VideoWidget plasma/widgets/videowidget.h <Plasma/Widgets/VideoWidget>
* a Video playing widget via Phonon, it encloses the
* Phonon::MediaObject and Phonon::AudioOutput too
*
* @short Provides a video player widget
* @since KDE4.3
*/
class PLASMA_EXPORT VideoWidget : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QString url READ url WRITE setUrl)
Q_PROPERTY(qint64 currentTime READ currentTime)
Q_PROPERTY(qint64 totalTime READ totalTime)
Q_PROPERTY(qint64 remainingTime READ remainingTime)
Q_PROPERTY(Controls usedControls READ usedControls WRITE setUsedControls)
Q_PROPERTY(bool controlsVisible READ controlsVisible WRITE setControlsVisible)
Q_PROPERTY(qint32 tickInterval READ tickInterval WRITE setTickInterval)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_ENUMS(Control)
public:
enum Control {
NoControls = 0,
Play = 1,
Pause = 2,
Stop = 4,
PlayPause = 8,
Previous = 16,
Next = 32,
Progress = 64,
Volume = 128,
OpenFile = 128,
DefaultControls = PlayPause|Progress|Volume|OpenFile
};
Q_DECLARE_FLAGS(Controls, Control)
explicit VideoWidget(QGraphicsWidget *parent = 0);
~VideoWidget();
/**
* Load a certain url that can be a local file or a remote one
* @param path resource to play
*/
void setUrl(const QString &url);
/**
* @return the url (local or remote) we are playing
*/
QString url() const;
/**
* @return the Phonon::MediaObject being used
* @see Phonon::MediaObject
*/
Q_INVOKABLE Phonon::MediaObject *mediaObject() const;
/**
* @return the Phonon::AudioOutput being used
* @see Phonon::AudioOutput
*/
Q_INVOKABLE Phonon::AudioOutput *audioOutput() const;
/**
* @return the current time of the current media file
*/
qint64 currentTime() const;
/**
* @return the total playing time of the current media file
*/
qint64 totalTime() const;
/**
* @return the time remaining to the current media file
*/
qint64 remainingTime() const;
/**
* Set what control widgets to use
*
* @param controls bitwise OR combination of Controls flags
* @see Controls
*/
void setUsedControls(const Controls controls);
/**
* @return the video controls that are used and shown
* @see Controls
*/
Controls usedControls() const;
/**
* Show/hide the main controls widget, if any of them is used
*
* @param visible if we want to show or hide the main controls
* @see setUsedControls()
*/
void setControlsVisible(bool visible);
/**
* @return true if the controls widget is being shown right now
*/
bool controlsVisible() const;
/**
* @param interval milliseconds the tick signal will be emitted
* @since 4.8
*/
void setTickInterval(qint64 interval);
/**
* @return milliseconds the tick signal will be emitted
* @see tickInterval()
* @since 4.8
*/
qint64 tickInterval() const;
/**
* Sets the stylesheet used to control the visual display of this VideoWidget
*
* @param stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* @return the native widget wrapped by this VideoWidget
*/
Phonon::VideoWidget *nativeWidget() const;
public Q_SLOTS:
/**
* Play the current file
*/
void play();
/**
* Pause the current file
*/
void pause();
/**
* Stop the current file
*/
void stop();
/**
* Jump at a given millisecond in the current file
* @param time where we want to jump
*/
void seek(qint64 time);
Q_SIGNALS:
/**
* Emitted regularly when the playing is progressing
* @param time where we are
*/
void tick(qint64 time);
/**
* Emitted an instant before the playback is finished
*/
void aboutToFinish();
/**
* The user pressed the "next" button
* @since 4.3
*/
void nextRequested();
/**
* The user pressed the "previous" button
* @since 4.3
*/
void previousRequested();
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
private:
VideoWidgetPrivate * const d;
Q_PRIVATE_SLOT(d, void playPause())
Q_PRIVATE_SLOT(d, void ticked(qint64 progress))
Q_PRIVATE_SLOT(d, void totalTimeChanged(qint64 time))
Q_PRIVATE_SLOT(d, void setPosition(int progress))
Q_PRIVATE_SLOT(d, void setVolume(int value))
Q_PRIVATE_SLOT(d, void volumeChanged(qreal value))
Q_PRIVATE_SLOT(d, void showOpenFileDialog())
Q_PRIVATE_SLOT(d, void stateChanged(Phonon::State newState, Phonon::State oldState))
Q_PRIVATE_SLOT(d, void hideControlWidget())
Q_PRIVATE_SLOT(d, void slidingCompleted())
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -1,339 +0,0 @@
/*
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
* Copyright 2010 Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QApplication>
#include <QStyleOptionGraphicsItem>
#include <fixx11h.h>
#include <QtWebKit/QWebFrame>
#include <QtWebKit/QWebPage>
#include <QtCore/QTimer>
#include <config-plasma.h>
#if !PLASMA_NO_KIO
#include <kio/accessmanager.h>
#endif
#include <kdebug.h>
#include "animator.h"
#include "plasma.h"
#include "widgets/webview.h"
#include "widgets/scrollwidget.h"
#include "graphicsview/private/animablegraphicswebview_p.h"
namespace Plasma
{
class WebViewPrivate
{
public:
WebViewPrivate(WebView *parent)
: q(parent)
{
}
void loadingFinished(bool success);
void dragTimeoutExpired();
WebView *q;
AnimableGraphicsWebView *webView;
ScrollWidget *scrollWidget;
bool loaded;
};
WebView::WebView(QGraphicsItem *parent)
: QGraphicsWidget(parent),
d(new WebViewPrivate(this))
{
d->loaded = false;
setAcceptTouchEvents(true);
setAcceptsHoverEvents(true);
setFlags(QGraphicsItem::ItemIsFocusable);
d->scrollWidget = new Plasma::ScrollWidget(this);
d->webView = new AnimableGraphicsWebView(d->scrollWidget);
d->scrollWidget->setWidget(d->webView);
d->scrollWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
d->scrollWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setDragToScroll(false);
QPalette palette = qApp->palette();
palette.setBrush(QPalette::Base, Qt::transparent);
d->webView->page()->setPalette(palette);
#if !PLASMA_NO_KIO
d->webView->page()->setNetworkAccessManager(new KIO::AccessManager(d->webView->page()));
#endif
connect(d->webView, SIGNAL(loadProgress(int)),
this, SIGNAL(loadProgress(int)));
connect(d->webView, SIGNAL(loadFinished(bool)),
this, SLOT(loadingFinished(bool)));
connect(d->webView, SIGNAL(urlChanged(QUrl)),
this, SIGNAL(urlChanged(QUrl)));
}
WebView::~WebView()
{
delete d;
}
void WebView::setUrl(const KUrl &url)
{
d->loaded = false;
d->webView->load(url);
}
KUrl WebView::url() const
{
return d->webView->url();
}
void WebView::setHtml(const QByteArray &html, const KUrl &baseUrl)
{
d->loaded = false;
d->webView->setContent(html, QString(), baseUrl);
}
void WebView::setHtml(const QString &html, const KUrl &baseUrl)
{
d->loaded = false;
d->webView->setHtml(html, baseUrl);
}
QString WebView::html() const
{
return d->webView->page()->mainFrame()->toHtml();
}
QRectF WebView::geometry() const
{
if (d->loaded) {
return QRectF(pos(), d->webView->page()->mainFrame()->geometry().size());
} else {
return QGraphicsWidget::geometry();
}
}
QSizeF WebView::contentsSize() const
{
return d->webView->page()->mainFrame()->contentsSize();
}
void WebView::setScrollPosition(const QPointF &position)
{
d->webView->setScrollPosition(position);
}
QPointF WebView::scrollPosition() const
{
return d->webView->scrollPosition();
}
QRectF WebView::viewportGeometry() const
{
return d->webView->page()->mainFrame()->geometry();
}
qreal WebView::zoomFactor() const
{
return d->webView->zoomFactor();
}
void WebView::setZoomFactor(const qreal zoom)
{
d->webView->setZoomFactor(zoom);
}
void WebView::setPage(QWebPage *page)
{
d->webView->setPage(page);
}
QWebPage *WebView::page() const
{
return d->webView->page();
}
QWebFrame *WebView::mainFrame() const
{
return d->webView->page()->mainFrame();
}
void WebView::setDragToScroll(bool drag)
{
// enable / disable scrollbars
if (drag) {
mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
} else {
mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAsNeeded);
mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded);
}
d->webView->setDragToScroll(drag);
d->scrollWidget->setFiltersChildEvents(drag);
}
bool WebView::dragToScroll()
{
return d->webView->dragToScroll();
}
void WebView::back()
{
d->webView->back();
}
void WebView::forward()
{
d->webView->forward();
}
void WebView::reload()
{
d->webView->reload();
}
void WebView::stop()
{
d->webView->stop();
}
void WebView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QGraphicsWidget::paint(painter, option, widget);
}
void WebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsWidget::mouseMoveEvent(event);
}
void WebView::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
QGraphicsWidget::hoverMoveEvent(event);
}
void WebView::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsWidget::mousePressEvent(event);
}
void WebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsWidget::mouseDoubleClickEvent(event);
}
void WebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsWidget::mouseReleaseEvent(event);
}
void WebView::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QGraphicsWidget::contextMenuEvent(event);
}
void WebView::wheelEvent(QGraphicsSceneWheelEvent *event)
{
QGraphicsWidget::wheelEvent(event);
}
void WebView::keyPressEvent(QKeyEvent * event)
{
QGraphicsWidget::keyPressEvent(event);
}
void WebView::keyReleaseEvent(QKeyEvent * event)
{
QGraphicsWidget::keyReleaseEvent(event);
}
void WebView::focusInEvent(QFocusEvent * event)
{
QGraphicsWidget::focusInEvent(event);
}
void WebView::focusOutEvent(QFocusEvent * event)
{
QGraphicsWidget::focusOutEvent(event);
}
void WebView::dragEnterEvent(QGraphicsSceneDragDropEvent * event)
{
QGraphicsWidget::dragEnterEvent(event);
}
void WebView::dragLeaveEvent(QGraphicsSceneDragDropEvent * event)
{
QGraphicsWidget::dragLeaveEvent(event);
}
void WebView::dragMoveEvent(QGraphicsSceneDragDropEvent * event)
{
QGraphicsWidget::dragMoveEvent(event);
}
void WebView::dropEvent(QGraphicsSceneDragDropEvent * event)
{
QGraphicsWidget::dropEvent(event);
}
QVariant WebView::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == QGraphicsItem::ItemSceneHasChanged) {
//FIXME: QWebPage _requires_ a QWidget view to not crash in places such as
// WebCore::PopupMenu::show() due to hostWindow()->platformPageClient() == NULL
// because QWebPage::d->client is NULL
//d->webView->page()->setView(viewFor(this));
}
return QGraphicsWidget::itemChange(change, value);
}
void WebView::setGeometry(const QRectF &geometry)
{
QGraphicsWidget::setGeometry(geometry);
d->scrollWidget->setGeometry(QRectF(0, 0, geometry.width(), geometry.height()));
d->webView->setGeometry(d->scrollWidget->viewportGeometry());
}
QSizeF WebView::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
{
if (which == Qt::PreferredSize) {
return d->webView->page()->mainFrame()->contentsSize();
} else {
return QGraphicsWidget::sizeHint(which, constraint);
}
}
void WebViewPrivate::loadingFinished(bool success)
{
loaded = success;
q->updateGeometry();
emit q->loadFinished(success);
q->update();
}
} // namespace Plasma
#include "moc_webview.cpp"

View File

@ -1,258 +0,0 @@
/*
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_WEBVIEW_H
#define PLASMA_WEBVIEW_H
#include <plasma/plasma_export.h>
#include <QGraphicsWidget>
#include <kurl.h>
class QWebPage;
class QWebFrame;
class QKeyEvent;
class QGraphicsSceneDragDropEvent;
class QGraphicsSceneMouseEvent;
class QGraphicsSceneWheelEvent;
class QRect;
namespace Plasma
{
class WebViewPrivate;
/**
* @class WebView plasma/widgets/webview.h <Plasma/Widgets/WebView>
*
* @short Provides a widget to display html content in Plasma.
*/
class PLASMA_EXPORT WebView : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(KUrl url READ url WRITE setUrl)
Q_PROPERTY(QString html READ html WRITE setHtml)
Q_PROPERTY(bool dragToScroll READ dragToScroll WRITE setDragToScroll)
Q_PROPERTY(QPointF scrollPosition READ scrollPosition WRITE setScrollPosition)
Q_PROPERTY(QSizeF contentsSize READ contentsSize)
Q_PROPERTY(QRectF viewportGeometry READ viewportGeometry)
Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor)
public:
explicit WebView(QGraphicsItem *parent = 0);
~WebView();
/**
* Sets the URL to display. Loading may happen asynchronously.
*
* @param url the location of the content to load.
*/
void setUrl(const KUrl &url);
/**
* @return the html content of the page
*/
KUrl url() const;
/**
* Sets the html to be shown along with a base URL to be used
* to resolve relative references.
*
* @param html the html (in utf8) to display in the content area
* @param baseUrl the base url for relative references
*/
void setHtml(const QByteArray &html, const KUrl &baseUrl = KUrl());
/**
* @return the html content of the page
*/
QString html() const;
/**
* Sets the html to be shown along with a base URL to be used
* to resolve relative references.
*
* @param html the html (in utf8) to display in the content area
* @param baseUrl the base url for relative references
*/
void setHtml(const QString &html, const KUrl &baseUrl = KUrl());
/**
* Reimplementation
*/
QRectF geometry() const;
/**
* @return the size of the internal widget
* @since 4.4
*/
QSizeF contentsSize() const;
/**
* Sets the position of the webpage relative to this widget
* @since 4.4
*/
void setScrollPosition(const QPointF &position);
/**
* @return the position of the webpage relative to this widget
* @since 4.4
*/
QPointF scrollPosition() const;
/**
* The geometry of the area that actually displays the web page
* @since 4.4
*/
QRectF viewportGeometry() const;
/**
* The zoom factor of the page
*
* @since 4.4
*/
qreal zoomFactor() const;
/**
* Sets the zoom factor of the page
*
* @since 4.4
*/
void setZoomFactor(const qreal zoom);
/**
* Sets the page to use in this item. The owner of the webpage remains,
* however if this WebView object is the owner of the current page,
* then the current page is deleted
*
* @param page the page to set in this view
*/
void setPage(QWebPage *page);
/**
* The QWebPage associated with this item. Useful when more
* of the features of the full QWebPage object need to be accessed.
*/
QWebPage *page() const;
/**
* The main web frame associated with this item.
*/
QWebFrame *mainFrame() const;
/**
* Sets if the page can be scrolled around by dragging the contents with the mouse
* @since 4.3
*/
void setDragToScroll(bool drag);
/**
* @return true if the page can be scrolled by dragging the mouse
* @since 4.3
*/
bool dragToScroll();
/**
* Reimplementation
*/
void setGeometry(const QRectF &geometry);
public Q_SLOTS:
/**
* Loads the previous document in the list of documents built by navigating links.
* @since 4.6
*/
void back();
/**
* Loads the next document in the list of documents built by navigating links.
* @since 4.6
*/
void forward();
/**
* Reloads the current document.
* @since 4.6
*/
void reload();
/**
* Stops loading the document.
* @since 4.6
*/
void stop();
Q_SIGNALS:
/**
* During loading progress, this signal is emitted. The values
* are always between 0 and 100, inclusive.
*
* @param percent the estimated amount the loading is complete
*/
void loadProgress(int percent);
/**
* This signal is emitted when loading is completed.
*
* @param success true if the content was loaded successfully,
* otherwise false
*/
void loadFinished(bool success);
/**
* url displayed by the web page changed
* @since 4.6
*/
void urlChanged(const QUrl &url);
protected:
/**
* Reimplementation
*/
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
void wheelEvent(QGraphicsSceneWheelEvent *event);
void keyPressEvent(QKeyEvent * event);
void keyReleaseEvent(QKeyEvent * event);
void focusInEvent(QFocusEvent * event);
void focusOutEvent(QFocusEvent * event);
void dragEnterEvent(QGraphicsSceneDragDropEvent * event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent * event);
void dragMoveEvent(QGraphicsSceneDragDropEvent * event);
void dropEvent(QGraphicsSceneDragDropEvent * event);
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
private:
Q_PRIVATE_SLOT(d, void loadingFinished(bool success))
WebViewPrivate * const d;
friend class WebViewPrivate;
};
} // namespace Plasma
#endif // Multiple incluson guard

View File

@ -1,168 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "<name>.h"
#include <<Native>>
#include <QPainter>
#include <kmimetype.h>
#include "theme.h"
#include "svg.h"
namespace Plasma
{
class <Name>Private
{
public:
<Name>Private(<Name> *w)
: q(w),
svg(0)
{
}
~<Name>Private()
{
delete svg;
}
void setPixmap(<Name> *q)
{
if (imagePath.isEmpty()) {
delete svg;
svg = 0;
return;
}
KMimeType::Ptr mime = KMimeType::findByPath(absImagePath);
QPixmap pm(q->size().toSize());
if (mime->is("image/svg+xml")) {
if (!svg || svg->imagePath() != imagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
}
QPainter p(&pm);
svg->paint(&p, pm.rect());
} else {
delete svg;
svg = 0;
pm = QPixmap(absImagePath);
}
//TODO: load image into widget
//static_cast<<Native>*>(q->widget())->setPixmappm(pm);
//static_cast<<Native>*>(q->widget())->setIcon(QIcon(pm));
}
<Name> *q;
QString imagePath;
QString absImagePath;
Svg *svg;
};
<Name>::<Name>(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new <Name>Private(this))
{
<Native>* native = new <Native>;
//TODO: forward signals
//connect(native, SIGNAL(()), this, SIGNAL(()));
setWidget(native);
native->setAttribute(Qt::WA_NoSystemBackground);
}
<Name>::~<Name>()
{
delete d;
}
void <Name>::setText(const QString &text)
{
static_cast<<Native>*>(widget())->setText(text);
}
QString <Name>::text() const
{
return static_cast<<Native>*>(widget())->text();
}
void <Name>::setImage(const QString &path)
{
if (d->imagePath == path) {
return;
}
delete d->svg;
d->svg = 0;
d->imagePath = path;
bool absolutePath = !path.isEmpty() &&
#ifdef Q_OS_WIN
!QDir::isRelativePath(path)
#else
(path[0] == '/' || path.startsWith(":/"))
#endif
;
if (absolutePath) {
d->absImagePath = path;
} else {
//TODO: package support
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap(this);
}
QString <Name>::image() const
{
return d->imagePath;
}
void <Name>::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString <Name>::styleSheet()
{
return widget()->styleSheet();
}
<Native>* <Name>::nativeWidget() const
{
return static_cast<<Native>*>(widget());
}
void <Name>::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap(this);
QGraphicsProxyWidget::resizeEvent(event);
}
} // namespace Plasma
#include <<name>.moc>

View File

@ -1,107 +0,0 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_<NAME>_H
#define PLASMA_<NAME>_H
#include <QGraphicsProxyWidget>
#include <plasma/plasma_export.h>
class <Native>;
namespace Plasma
{
class <Name>Private;
/**
* @class <Name> plasma/widgets/<name>.h <Plasma/Widgets/<Name>>
*
* @short Provides a plasma-themed <Native>.
*/
class PLASMA_EXPORT <Name> : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QString image READ image WRITE setImage)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(<Native>* nativeWidget READ nativeWidget)
public:
explicit <Name>(QGraphicsWidget *parent = 0);
~<Name>();
/**
* Sets the display text for this <Name>
*
* @arg text the text to display; should be translated.
*/
void setText(const QString &text);
/**
* @return the display text
*/
QString text() const;
/**
* Sets the path to an image to display.
*
* @arg path the path to the image; if a relative path, then a themed image will be loaded.
*/
void setImage(const QString &path);
/**
* @return the image path being displayed currently, or an empty string if none.
*/
QString image() const;
/**
* Sets the stylesheet used to control the visual display of this <Name>
*
* @arg stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* @return the native widget wrapped by this <Name>
*/
<Native>* nativeWidget() const;
Q_SIGNALS:
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
private:
Q_PRIVATE_SLOT(d, void setPixmap())
<Name>Private * const d;
};
} // namespace Plasma
#endif // multiple inclusion guard