[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdeplasma-addons/applets/pastebin
From: Sebastian Kügler <sebas () kde ! org>
Date: 2009-03-01 1:59:10
Message-ID: 1235872750.251543.14144.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 933485 by sebas:
Introducing of the states
- we now have two enums, one keeping the applet's state, one for
tracking user interaction
- "drop!" is written on top of the applet
- hovering is already switched to the interactionstate stuff
- resize the font in constraintsEvent
- thanks to Zack for spotting a qreal * 255 issue, so we can use the
faster path for painting now \o/
M +70 -6 pastebin.cpp
M +29 -1 pastebin.h
--- trunk/KDE/kdeplasma-addons/applets/pastebin/pastebin.cpp #933484:933485
@@ -43,6 +43,8 @@
#include <kio/global.h>
#include <kio/job.h>
+#include <Plasma/Theme>
+
Pastebin::Pastebin(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args), m_graphicsWidget(0), m_textServer(0),
m_imageServer(0), m_textBackend(0), m_imageBackend(0)
@@ -121,9 +123,50 @@
setImageServer(imageBackend);
resize(200, 200);
setBackgroundHints(TranslucentBackground);
+ m_actionState = Idle;
+ m_interactionState = Waiting;
}
+void Pastebin::updateTheme()
+{
+ m_font = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
+}
+
+void Pastebin::setInteractionState(InteractionState state)
+{
+
+ switch (state ) {
+
+ case Hovered:
+ kDebug() << "Hovered";
+ showOverlay(true);
+ break;
+ case Waiting:
+ kDebug() << "Waiting";
+ showOverlay(false);
+ break;
+ case DraggedOver:
+ kDebug() << "DraggedOver";
+ showOverlay(true);
+ break;
+ case Rejected:
+ kDebug() << "Rejected";
+ break;
+ default:
+ break;
+ }
+ m_interactionState = state;
+}
+
+void Pastebin::setActionState(ActionState state)
+{
+
+
+
+ m_actionState = state;
+}
+
QGraphicsWidget *Pastebin::graphicsWidget()
{
if (m_graphicsWidget) {
@@ -149,6 +192,16 @@
return m_graphicsWidget;
}
+void Pastebin::constraintsEvent(Plasma::Constraints constraints)
+{
+ if (constraints & (Plasma::FormFactorConstraint | Plasma::SizeConstraint)) {
+ int minSize = KGlobalSettings::smallestReadableFont().pointSize();
+ int dynSize = qMin(contentsRect().width(), contentsRect().height()) / 6;
+ kDebug() << "Min : Dyn" << minSize << dynSize << qMax(minSize, dynSize);
+ m_font.setPointSize(qMax(minSize, dynSize));
+ }
+}
+
int Pastebin::iconSize()
{
// return the biggest fitting icon size from KIconLoader
@@ -194,7 +247,7 @@
QPointF iconOrigin = QPointF(contentsRect.left() + (contentsRect.width() - \
iconsize) / 2,
contentsRect.top() + (contentsRect.height() - \
iconsize) / 2);
- if (false && !p->paintEngine()->hasFeature(QPaintEngine::ConstantOpacity)) {
+ if (!p->paintEngine()->hasFeature(QPaintEngine::ConstantOpacity)) {
// see http://techbase.kde.org/Development/Tutorials/Graphics/Performance#QPainter::setOpacity.28.29
// Doesn't work yet ... but should be much faster on X11
kDebug() << "new painter ..." << pix_alpha << iconpix.rect();
@@ -208,11 +261,11 @@
painter.drawPixmap(QPoint(0,0), iconpix);
// For testing ...
- painter.setBrush(QColor("green"));
+ //painter.setBrush(QColor("green"));
painter.drawRect(iconpix.rect());
painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
- painter.fillRect(iconpix.rect(), QColor(0, 0, 0, pix_alpha));
+ painter.fillRect(iconpix.rect(), QColor(0, 0, 0, pix_alpha * 255));
painter.end();
p->drawPixmap(iconOrigin, pixmap);
@@ -224,18 +277,19 @@
p->drawPixmap(iconOrigin, iconpix);
p->setOpacity(o);
}
+ p->setFont(m_font);
+ p->drawText(contentsRect, Qt::AlignCenter, i18n("Drop!"));
}
void Pastebin::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
- showOverlay(true);
- m_isHovered = true;
+ setInteractionState(Hovered);
Applet::hoverEnterEvent(event);
}
void Pastebin::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
- showOverlay(false);
+ setInteractionState(Waiting);
Applet::hoverLeaveEvent(event);
}
@@ -352,9 +406,19 @@
void Pastebin::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
+ InteractionState istate = Rejected;
if (event->mimeData()->hasFormat("text/plain")) {
event->acceptProposedAction();
}
+ foreach (const QString f, event->mimeData()->formats()) {
+ if (f.indexOf("image/") != -1) {
+ istate = DraggedOver;
+ }
+ }
+ if (event->mimeData()->hasImage()) {
+ istate = DraggedOver;
+ }
+ setInteractionState(istate);
}
void Pastebin::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
--- trunk/KDE/kdeplasma-addons/applets/pastebin/pastebin.h #933484:933485
@@ -56,12 +56,31 @@
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option,
const QRect &contents);
+ void constraintsEvent(Plasma::Constraints constraints);
QGraphicsWidget *graphicsWidget();
enum textServers { PASTEBINCA, PASTEBINCOM };
enum imageServers { IMAGEBINCA, IMAGESHACK };
+ enum InteractionState { /* What is the user doing, used for visual feedback on \
user actions */ + Off = 0, /* Not set */
+ Waiting = 1, /* Applet hanging around idle */
+ Hovered = 2, /* "empty" mouse over effect */
+ Rejected = 3, /* unsuitable content is dragged over us */
+ DraggedOver = 5 /* suitable content is dragged over us */
+ };
+ //Q_DECLARE_FLAGS(InteractionStates, InteractionState)
+
+ enum ActionState { /* What is the applet doing */
+ Unset = 0, /* Not set */
+ Idle = 1, /* The applet has been started but nothing done yet */
+ IdleError = 2, /* The last action went wrong, but we're ready to give it \
another try */ + IdleSuccess = 4, /* Last action succeeded */
+ Sending = 8 /* Sending data to the server, waiting for reply */
+ };
+ //Q_DECLARE_FLAGS(ActionStates, ActionState)
+
public slots:
void configAccepted();
@@ -81,15 +100,24 @@
private Q_SLOTS:
void animationUpdate(qreal progress);
+ void updateTheme();
private:
int iconSize();
void showOverlay(bool show);
+
+ void setInteractionState(InteractionState state);
+ void setActionState(ActionState state);
+
+ ActionState m_actionState;
+ InteractionState m_interactionState;
+
+ bool m_isHovered;
bool m_fadeIn;
- bool m_isHovered;
int m_animId;
qreal m_alpha;
+ QFont m_font;
QGraphicsWidget *m_graphicsWidget;
DraggableLabel *m_resultsLabel;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic