A last couple of api changes before the move to kdelibs:
* in class Extender rename setExtenderAppearance to setAppearance. * in class ExtenderItem rename moveBackToSource to returnToSource. * in class ExtenderItem addition of showCloseAction() and hideCloseAction(). ... and some minor tweaks in the implementation. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=879670
This commit is contained in:
parent
1bf93bb2d3
commit
babf165d5d
@ -141,7 +141,7 @@ ExtenderItem *Extender::item(const QString &name) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Extender::setExtenderAppearance(Appearance appearance)
|
||||
void Extender::setAppearance(Appearance appearance)
|
||||
{
|
||||
if (d->appearance == appearance) {
|
||||
return;
|
||||
@ -151,7 +151,7 @@ void Extender::setExtenderAppearance(Appearance appearance)
|
||||
d->updateBorders();
|
||||
}
|
||||
|
||||
Extender::Appearance Extender::extenderAppearance() const
|
||||
Extender::Appearance Extender::appearance() const
|
||||
{
|
||||
return d->appearance;
|
||||
}
|
||||
|
@ -142,12 +142,12 @@ class PLASMA_EXPORT Extender : public QGraphicsWidget
|
||||
* want to call this function in your applet's constraintsEvent, allthough this is already
|
||||
* done for you when using PopupApplet at base class for your applet. Defaults to NoBorders.
|
||||
*/
|
||||
void setExtenderAppearance(Appearance appearance);
|
||||
void setAppearance(Appearance appearance);
|
||||
|
||||
/**
|
||||
* @return the current way of rendering extender items that is used.
|
||||
*/
|
||||
Appearance extenderAppearance() const;
|
||||
Appearance appearance() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
@ -162,9 +162,8 @@ void ExtenderItem::setWidget(QGraphicsItem *widget)
|
||||
{
|
||||
widget->setParentItem(this);
|
||||
|
||||
QSizeF iconSize = d->dragger->elementSize("hint-preferred-icon-size");
|
||||
QSizeF panelSize(QSizeF(size().width() - d->bgLeft - d->bgRight,
|
||||
iconSize.height() + d->dragTop + d->dragBottom));
|
||||
d->iconSize() + d->dragTop + d->dragBottom));
|
||||
widget->setPos(QPointF(d->bgLeft + d->dragLeft, panelSize.height() +
|
||||
d->bgTop + d->dragTop));
|
||||
d->widget = widget;
|
||||
@ -308,6 +307,26 @@ QAction *ExtenderItem::action(const QString &name) const
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderItem::showCloseButton()
|
||||
{
|
||||
if (d->destroyActionVisibility) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->destroyActionVisibility = true;
|
||||
d->updateToolBox();
|
||||
}
|
||||
|
||||
void ExtenderItem::hideCloseButton()
|
||||
{
|
||||
if (!d->destroyActionVisibility) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->destroyActionVisibility = false;
|
||||
d->updateToolBox();
|
||||
}
|
||||
|
||||
void ExtenderItem::destroy()
|
||||
{
|
||||
if (d->mousePressed) {
|
||||
@ -387,7 +406,7 @@ void ExtenderItem::setCollapsed(bool collapsed)
|
||||
d->extender->d->adjustSize();
|
||||
}
|
||||
|
||||
void ExtenderItem::moveBackToSource()
|
||||
void ExtenderItem::returnToSource()
|
||||
{
|
||||
if (!d->sourceApplet) {
|
||||
return;
|
||||
@ -421,7 +440,6 @@ void ExtenderItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
//set the font for the title.
|
||||
Plasma::Theme *theme = Plasma::Theme::defaultTheme();
|
||||
QFont font = theme->font(Plasma::Theme::DefaultFont);
|
||||
font.setPointSize(KGlobalSettings::smallestReadableFont().pointSize());
|
||||
font.setWeight(QFont::Bold);
|
||||
|
||||
//create a pixmap with the title that is faded out at the right side of the titleRect.
|
||||
@ -729,6 +747,7 @@ ExtenderItemPrivate::ExtenderItemPrivate(ExtenderItem *extenderItem, Extender *h
|
||||
title(QString()),
|
||||
mousePressed(false),
|
||||
mouseOver(false),
|
||||
destroyActionVisibility(false),
|
||||
expirationTimer(0)
|
||||
{
|
||||
dragLeft = dragTop = dragRight = dragBottom = 0;
|
||||
@ -743,9 +762,8 @@ ExtenderItemPrivate::~ExtenderItemPrivate()
|
||||
//returns a Rect containing the area of the detachable where the draghandle will be drawn.
|
||||
QRectF ExtenderItemPrivate::dragHandleRect()
|
||||
{
|
||||
QSizeF iconSize = dragger->elementSize("hint-preferred-icon-size");
|
||||
QSizeF panelSize(QSizeF(q->size().width() - bgLeft - bgRight,
|
||||
iconSize.height() + dragTop + dragBottom));
|
||||
iconSize() + dragTop + dragBottom));
|
||||
return QRectF(QPointF(bgLeft, bgTop), panelSize);
|
||||
}
|
||||
|
||||
@ -801,10 +819,9 @@ void ExtenderItemPrivate::updateToolBox()
|
||||
Q_ASSERT(dragger);
|
||||
Q_ASSERT(toolboxLayout);
|
||||
|
||||
uint iconHeight = dragger->elementSize("hint-preferred-icon-size").height();
|
||||
uint iconHeight = iconSize();
|
||||
|
||||
//TODO: only delete items that actually have to be deleted, current performance is horrible.
|
||||
//clean the layout.
|
||||
while (toolboxLayout->count()) {
|
||||
QGraphicsLayoutItem *icon = toolboxLayout->itemAt(0);
|
||||
QGraphicsWidget *widget = dynamic_cast<QGraphicsWidget*>(icon);
|
||||
@ -833,7 +850,19 @@ void ExtenderItemPrivate::updateToolBox()
|
||||
returnToSource->setMaximumSize(iconSize);
|
||||
|
||||
toolboxLayout->addItem(returnToSource);
|
||||
QObject::connect(returnToSource, SIGNAL(clicked()), q, SLOT(moveBackToSource()));
|
||||
QObject::connect(returnToSource, SIGNAL(clicked()), q, SLOT(returnToSource()));
|
||||
}
|
||||
|
||||
//add the close icon if desired.
|
||||
if (destroyActionVisibility) {
|
||||
IconWidget *destroyAction = new IconWidget(q);
|
||||
destroyAction->setSvg("widgets/configuration-icons", "close");
|
||||
QSizeF iconSize = destroyAction->sizeFromIconSize(iconHeight);
|
||||
destroyAction->setMinimumSize(iconSize);
|
||||
destroyAction->setMaximumSize(iconSize);
|
||||
|
||||
toolboxLayout->addItem(destroyAction);
|
||||
QObject::connect(destroyAction, SIGNAL(clicked()), q, SLOT(destroy()));
|
||||
}
|
||||
|
||||
toolboxLayout->updateGeometry();
|
||||
@ -848,7 +877,7 @@ void ExtenderItemPrivate::repositionToolbox()
|
||||
{
|
||||
QSizeF minimum = toolboxLayout->minimumSize();
|
||||
toolbox->setPos(q->size().width() - minimum.width() - bgRight,
|
||||
((dragHandleRect().height() + dragTop + dragBottom)/2) -
|
||||
(dragHandleRect().height()/2) -
|
||||
(minimum.height()/2) + bgTop);
|
||||
}
|
||||
|
||||
@ -909,8 +938,6 @@ Applet *ExtenderItemPrivate::hostApplet() const
|
||||
|
||||
void ExtenderItemPrivate::themeChanged()
|
||||
{
|
||||
QSizeF iconSize = dragger->elementSize("hint-preferred-icon-size");
|
||||
|
||||
background->setImagePath("widgets/extender-background");
|
||||
if (mousePressed) {
|
||||
background->setEnabledBorders(FrameSvg::AllBorders);
|
||||
@ -923,14 +950,14 @@ void ExtenderItemPrivate::themeChanged()
|
||||
dragger->getMargins(dragLeft, dragTop, dragRight, dragBottom);
|
||||
|
||||
QSizeF panelSize(QSizeF(q->size().width() - bgLeft - bgRight,
|
||||
iconSize.height() + dragTop + dragBottom));
|
||||
iconSize() + dragTop + dragBottom));
|
||||
|
||||
//resize the collapse icon.
|
||||
collapseIcon->resize(collapseIcon->sizeFromIconSize(iconSize.height()));
|
||||
collapseIcon->resize(collapseIcon->sizeFromIconSize(iconSize()));
|
||||
|
||||
//reposition the collapse icon based on the new margins and size.
|
||||
collapseIcon->setPos(bgLeft + dragLeft,
|
||||
(panelSize.height() + dragTop + dragBottom)/2 -
|
||||
panelSize.height()/2 -
|
||||
collapseIcon->size().height()/2 + bgTop);
|
||||
|
||||
//reposition the widget based on the new margins.
|
||||
@ -956,6 +983,17 @@ void ExtenderItemPrivate::sourceAppletRemoved()
|
||||
updateToolBox();
|
||||
}
|
||||
|
||||
qreal ExtenderItemPrivate::iconSize()
|
||||
{
|
||||
QSizeF size = dragger->elementSize("hint-preferred-icon-size");
|
||||
|
||||
Plasma::Theme *theme = Plasma::Theme::defaultTheme();
|
||||
QFont font = theme->font(Plasma::Theme::DefaultFont);
|
||||
QFontMetrics fm(font);
|
||||
|
||||
return qMax(size.height(), (qreal) fm.height());
|
||||
}
|
||||
|
||||
uint ExtenderItemPrivate::s_maxExtenderItemId = 0;
|
||||
|
||||
} // namespace Plasma
|
||||
|
@ -216,7 +216,18 @@ class PLASMA_EXPORT ExtenderItem : public QGraphicsWidget
|
||||
/**
|
||||
* Returns the extender item to its source applet.
|
||||
*/
|
||||
void moveBackToSource();
|
||||
void returnToSource();
|
||||
|
||||
/**
|
||||
* Shows a close button in this item's drag handle. By default a close button will not be
|
||||
* shown.
|
||||
*/
|
||||
void showCloseButton();
|
||||
|
||||
/**
|
||||
* Hides the close button in this item's drag handle.
|
||||
*/
|
||||
void hideCloseButton();
|
||||
|
||||
protected:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
|
@ -186,7 +186,7 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
|
||||
if (gWidget) {
|
||||
Extender *extender = qobject_cast<Extender*>(gWidget);
|
||||
if (extender) {
|
||||
extender->setExtenderAppearance(Extender::NoBorders);
|
||||
extender->setAppearance(Extender::NoBorders);
|
||||
}
|
||||
|
||||
lay->addItem(gWidget);
|
||||
@ -242,11 +242,11 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
|
||||
Extender *extender = qobject_cast<Extender*>(gWidget);
|
||||
if (extender) {
|
||||
if (q->formFactor() == MediaCenter || q->formFactor() == Planar) {
|
||||
extender->setExtenderAppearance(Extender::NoBorders);
|
||||
extender->setAppearance(Extender::NoBorders);
|
||||
} else if (q->location() == TopEdge) {
|
||||
extender->setExtenderAppearance(Extender::TopDownStacked);
|
||||
extender->setAppearance(Extender::TopDownStacked);
|
||||
} else {
|
||||
extender->setExtenderAppearance(Extender::BottomUpStacked);
|
||||
extender->setAppearance(Extender::BottomUpStacked);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,14 +37,10 @@ ExtenderApplet::~ExtenderApplet()
|
||||
void ExtenderApplet::init()
|
||||
{
|
||||
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(this);
|
||||
layout->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(0);
|
||||
setLayout(layout);
|
||||
|
||||
qreal left, top, right, bottom;
|
||||
getContentsMargins(&left, &top, &right, &bottom);
|
||||
extender()->setExtenderAppearance(Plasma::Extender::NoBorders);
|
||||
extender()->setAppearance(Plasma::Extender::NoBorders);
|
||||
extender()->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
||||
|
||||
connect(extender(), SIGNAL(itemDetached(Plasma::ExtenderItem*)),
|
||||
|
@ -56,6 +56,7 @@ class ExtenderItemPrivate
|
||||
Applet *hostApplet() const;
|
||||
void themeChanged();
|
||||
void sourceAppletRemoved();
|
||||
qreal iconSize();
|
||||
|
||||
ExtenderItem *q;
|
||||
|
||||
@ -90,6 +91,7 @@ class ExtenderItemPrivate
|
||||
|
||||
bool mousePressed;
|
||||
bool mouseOver;
|
||||
bool destroyActionVisibility;
|
||||
|
||||
QTimer *expirationTimer;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user