[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [sflphone-kde/october2012_ui] src: [ #16349 ] Implement multi-tip support and move the concrete impl
From: Emmanuel Lepage Vallee <emmanuel.lepage () savoirfairelinux ! com>
Date: 2012-11-02 22:07:28
Message-ID: 20121102220728.1CB1FA6078 () git ! kde ! org
[Download RAW message or body]
Git commit 893dec2dc8779d117f637785fac1dc9d6dfe8824 by Emmanuel Lepage Vallee.
Committed on 02/11/2012 at 23:07.
Pushed by lepagevalleeemmanuel into branch 'october2012_ui'.
[ #16349 ] Implement multi-tip support and move the concrete implementation to the \
widgets folder
M +1 -0 src/CMakeLists.txt
M +6 -6 src/callview.cpp
M +2 -0 src/callview.h
M +6 -8 src/klib/tip.cpp
M +3 -4 src/klib/tip.h
M +18 -14 src/klib/tipanimationwrapper.cpp
M +5 -1 src/klib/tipanimationwrapper.h
M +34 -9 src/klib/tipmanager.cpp
M +6 -7 src/klib/tipmanager.h
A +53 -0 src/widgets/tips/dialpadtip.cpp [License: LGPL (v2.1+)]
A +48 -0 src/widgets/tips/dialpadtip.h [License: LGPL (v2.1+)]
http://commits.kde.org/sflphone-kde/893dec2dc8779d117f637785fac1dc9d6dfe8824
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 62e319e..c78224e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -60,6 +60,7 @@ SET(
widgets/immanager.cpp
widgets/imtab.cpp
widgets/callviewoverlaytoolbar.cpp
+ widgets/tips/dialpadtip.cpp
# widgets/acceleratedvideowidget.cpp
callview.cpp
)
diff --git a/src/callview.cpp b/src/callview.cpp
index a64f31d..4a48a34 100644
--- a/src/callview.cpp
+++ b/src/callview.cpp
@@ -50,6 +50,7 @@
#include "sflphoneaccessibility.h"
#include "widgets/conferencebox.h"
#include "widgets/callviewoverlaytoolbar.h"
+#include "widgets/tips/dialpadtip.h"
#include "klib/tipmanager.h"
///CallTreeItemDelegate: Delegates for CallTreeItem
@@ -275,10 +276,9 @@ CallView::CallView(QWidget* parent) : \
QTreeWidget(parent),m_pActiveOverlay(0),m_ QGridLayout* gl = new QGridLayout \
( m_pTransferOverlay ); QLabel* lblImg = new QLabel ( image \
); m_pCanvasToolbar = new CallViewOverlayToolbar(this);
- m_pTip = new TipManager(this,
- KStandardDirs::locate("data",
- "sflphone-client-kde/tips/keyboard.svg"),
- i18n("Use the dialpad below or start \
typing a number. Use the dialpad below or start typing a number. Use the \
dsadasdialpad below or start typing a number. Use thasdasde dialpad below or \
sasdasdtart typing a number. "),4); + m_pTip2 = new DialPadTip(this);
+ m_pTip = new TipManager(this);
+
m_pTransferOverlay->setVisible(false);
m_pTransferOverlay->resize(size());
@@ -998,11 +998,11 @@ void CallView::moveSelectedItem( Qt::Key direction )
setCurrentIndex(moveCursor(QAbstractItemView::MoveRight,Qt::NoModifier));
}
else if (direction == Qt::Key_Up) {
- m_pTip->setCurrentTip(true);
+ m_pTip->setCurrentTip(m_pTip2);
setCurrentIndex(moveCursor(QAbstractItemView::MoveUp ,Qt::NoModifier));
}
else if (direction == Qt::Key_Down) {
- m_pTip->setCurrentTip(false);
+ m_pTip->setCurrentTip(nullptr);
setCurrentIndex(moveCursor(QAbstractItemView::MoveDown ,Qt::NoModifier));
}
}
diff --git a/src/callview.h b/src/callview.h
index 833fb27..6a81746 100644
--- a/src/callview.h
+++ b/src/callview.h
@@ -39,6 +39,7 @@ class CallTreeItem;
class CallTreeItemDelegate;
class CallViewOverlayToolbar;
class TipManager;
+class Tip;
//Typedef
typedef CallModel<CallTreeItem*,QTreeWidgetItem*> TreeWidgetCallModel;
@@ -117,6 +118,7 @@ class CallView : public QTreeWidget {
Call* m_pCallPendingTransfer;
CallViewOverlayToolbar* m_pCanvasToolbar ;
TipManager* m_pTip ;
+ Tip* m_pTip2 ;
protected:
//Reimlementation
diff --git a/src/klib/tip.cpp b/src/klib/tip.cpp
index c714e9f..617d245 100644
--- a/src/klib/tip.cpp
+++ b/src/klib/tip.cpp
@@ -30,10 +30,9 @@
#include "tipmanager.h"
///Constructor
-Tip::Tip(QWidget* parent,const QString& path, const QString& text, int maxLine) : \
QObject(parent),m_OriginalText(text),m_MaxLine(maxLine),m_Position(TipPosition::Bottom),m_IsMaxSize(false),m_pR(nullptr),
+Tip::Tip(QWidget* parent,const QString& path, const QString& text) : \
QObject(parent),m_OriginalText(text),m_Position(TipPosition::Bottom),m_IsMaxSize(false),m_pR(nullptr),
m_OriginalPalette(parent->palette()),m_AnimationIn(TipAnimation::TranslationTop),m_AnimationOut(TipAnimation::TranslationTop),m_pFont(nullptr)
{
- loadSvg(path);
}
///Destructor
@@ -81,7 +80,7 @@ QSize Tip::reload(const QRect& availableSize)
//If the widget is subclassed, this would allow decorations to be added like \
images paintDecorations(p,textRect);
-
+
//Set the size from the RECT //TODO redundant
m_CurrentSize = QSize(m_CurrentRect.width(),m_CurrentRect.height());
}
@@ -96,7 +95,7 @@ QRect Tip::getTextRect(const QString& text)
}
///Check if the thene color scheme is darker than #888888
-///@return true = bright, false = dark
+///@return true = dark, false = bright
bool Tip::brightOrDarkBase()
{
QColor color = m_OriginalPalette.base().color();
@@ -106,14 +105,13 @@ bool Tip::brightOrDarkBase()
QRect Tip::getDecorationRect()
{
- return QRect(0,0,m_CurrentSize.width()-2*PADDING,60);
+ return QRect();
}
void Tip::paintDecorations(QPainter& p, const QRect& textRect)
{
- if (!m_pR)
- m_pR = new QSvgRenderer(m_OriginalFile);
- m_pR->render(&p,QRect(m_CurrentRect.width() - PADDING - 50*2.59143327842 - 10 \
,textRect.y()+textRect.height() + 10,50*2.59143327842,50)); + Q_UNUSED(p)
+ Q_UNUSED(textRect)
}
const QFont& Tip::font()
diff --git a/src/klib/tip.h b/src/klib/tip.h
index 648c232..8383f77 100644
--- a/src/klib/tip.h
+++ b/src/klib/tip.h
@@ -36,13 +36,13 @@ class QSvgRenderer;
class QPainter;
///A tip to be passed to the TipLoader
-class Tip : public QObject
+class LIB_EXPORT Tip : public QObject
{
Q_OBJECT
public:
- friend class TipManager;
friend class TipAnimationWrapper;
- Tip(QWidget* parent = nullptr,const QString& path="", const QString& text="", int \
maxLine=4); +
+ Tip(QWidget* parent = nullptr,const QString& path="", const QString& text="");
virtual ~Tip();
//Enum
@@ -70,7 +70,6 @@ protected:
QByteArray m_OriginalFile ;
QString m_OriginalText ;
QStringList m_Lines ;
- int m_MaxLine ;
QSize m_CurrentSize ;
QImage m_CurrentImage ;
QRect m_CurrentRect ;
diff --git a/src/klib/tipanimationwrapper.cpp b/src/klib/tipanimationwrapper.cpp
index 607d95a..dc22534 100644
--- a/src/klib/tipanimationwrapper.cpp
+++ b/src/klib/tipanimationwrapper.cpp
@@ -25,7 +25,8 @@
#include "tip.h"
#include "tipmanager.h"
-TipAnimationWrapper::TipAnimationWrapper(Tip* aTip, TipManager* parent) : \
QObject(parent),m_MaxStep(15),m_Step(0),m_pTimer(nullptr),m_pTip(aTip),m_TipSize(QSize(0,0))
+TipAnimationWrapper::TipAnimationWrapper(TipManager* parent) : \
QObject(parent),m_MaxStep(15),m_Step(0),m_pTimer(nullptr),m_TipSize(QSize(0,0)), \
+m_pTip(nullptr) {
connect(parent,SIGNAL(sizeChanged(QRect,bool)),this,SLOT(sizeChanged(QRect,bool)));
}
@@ -53,7 +54,7 @@ void TipAnimationWrapper::sizeChanged(QRect rect,bool ignoreAnim)
const QImage& TipAnimationWrapper::currentImage()
{
- return m_CurrentImage;
+ return (m_pTip)?m_pTip->m_CurrentImage:m_CurrentImage;
}
QSize TipAnimationWrapper::tipSize()
@@ -67,24 +68,27 @@ QSize TipAnimationWrapper::tipSize()
*/
void TipAnimationWrapper::start(bool show)
{
- if (!m_pTimer) {
- m_pTimer = new QTimer(this);
- connect(m_pTimer,SIGNAL(timeout()),this,SLOT(step()));
- }
+ if (m_pTip) {
+ if (!m_pTimer) {
+ m_pTimer = new QTimer(this);
+ connect(m_pTimer,SIGNAL(timeout()),this,SLOT(step()));
+ }
- m_Step = 0;
- m_CurrentAnimation = show?m_pTip->m_AnimationIn:m_pTip->m_AnimationOut;
- m_FadeDirection = show;
- if (m_CurrentAnimation != Tip::None)
- m_pTimer->start(33);
- else {
- step();
- emit animationEnded();
+ m_Step = 0;
+ m_CurrentAnimation = show?m_pTip->m_AnimationIn:m_pTip->m_AnimationOut;
+ m_FadeDirection = show;
+ if (m_CurrentAnimation != Tip::None)
+ m_pTimer->start(33);
+ else {
+ step();
+ emit animationEnded();
+ }
}
}
void TipAnimationWrapper::step()
{
+ if (!m_pTip) return;
m_Step++;
if (m_Step > m_MaxStep) {
m_Step = 0;
diff --git a/src/klib/tipanimationwrapper.h b/src/klib/tipanimationwrapper.h
index a7c2ab3..f2c804e 100644
--- a/src/klib/tipanimationwrapper.h
+++ b/src/klib/tipanimationwrapper.h
@@ -40,16 +40,20 @@ class TipAnimationWrapper : public QObject
{
Q_OBJECT
public:
- TipAnimationWrapper(Tip* aTip, TipManager* parent);
+ TipAnimationWrapper(TipManager* parent);
virtual ~TipAnimationWrapper();
//Mutator
void start(bool show = true);
+ //Setter
+ void setTip(Tip* tip) {m_pTip = tip;}
+
//Getter
const QImage& currentImage();
QSize tipSize();
bool isRunning();
+ Tip* tip() {return m_pTip;}
private:
//Attributes
diff --git a/src/klib/tipmanager.cpp b/src/klib/tipmanager.cpp
index b034c2e..e607dad 100644
--- a/src/klib/tipmanager.cpp
+++ b/src/klib/tipmanager.cpp
@@ -37,15 +37,16 @@ bool ResizeEventFilter::eventFilter(QObject *obj, QEvent *event)
}
///Constructor
-TipManager::TipManager(QTreeView* parent, const QString& path, const QString& text, \
int maxLine):QObject(parent),
-m_OriginalPalette(parent->palette()),m_pParent(parent),m_BottomMargin(0),m_TopMargin(0),m_Tip(parent,path,text,maxLine),
-m_pAnim(&m_Tip,this)
+TipManager::TipManager(QTreeView* parent):QObject(parent),
+m_OriginalPalette(parent->palette()),m_pParent(parent),m_BottomMargin(0),m_TopMargin(0),
+m_pAnim(this),m_pCurrentTip(nullptr)
{
ResizeEventFilter* filter = new ResizeEventFilter(this);
parent->installEventFilter(filter);
reload();
connect(&m_pAnim,SIGNAL(animationStep(FrameDescription)),this,SLOT(animationStep(FrameDescription)));
+ connect(&m_pAnim,SIGNAL(animationEnded()),this,SLOT(animationEnded()));
}
///Get the current image
@@ -91,15 +92,38 @@ void TipManager::setBottomMargin(int margin)
}
///Set the current tip, hide the previous one, if any
-void TipManager::setCurrentTip(bool tip)
+void TipManager::setCurrentTip(Tip* tip)
+{
+ if (!m_pCurrentTip && tip) {
+ setCurrentTip_private(tip);
+ }
+ else if (m_pCurrentTip) {
+ m_pAnim.start(false);
+ changeSize(true);
+ m_lTipQueue << tip;
+ }
+ else if (tip) {
+ m_lTipQueue << tip;
+ }
+}
+
+void TipManager::setCurrentTip_private(Tip* tip)
{
if (tip != m_pCurrentTip) {
+ m_pAnim.setTip(tip);
m_pCurrentTip = tip;
- m_pAnim.start(tip);
+ m_pAnim.start(m_pCurrentTip != nullptr);
changeSize(true);
}
}
+void TipManager::animationEnded()
+{
+ if (m_lTipQueue.size()) {
+ setCurrentTip_private(m_lTipQueue.takeFirst());
+ }
+}
+
///Callback for new animation frame
void TipManager::animationStep(FrameDescription desc)
{
@@ -110,8 +134,9 @@ void TipManager::animationStep(FrameDescription desc)
///Callback when size change
void TipManager::changeSize(bool ignoreAnim)
{
- int width(m_pParent->width()),height(m_pParent->height());
- int effectiveHeight = height-m_BottomMargin-m_TopMargin;
-// qDebug() << height << (height-effectiveHeight) << effectiveHeight << \
(width-30);
- emit sizeChanged(QRect(15,m_TopMargin,width-30,effectiveHeight),ignoreAnim);
+ if (m_pCurrentTip) {
+ int width(m_pParent->width()),height(m_pParent->height());
+ int effectiveHeight = height-m_BottomMargin-m_TopMargin;
+ emit sizeChanged(QRect(15,m_TopMargin,width-30,effectiveHeight),ignoreAnim);
+ }
}
\ No newline at end of file
diff --git a/src/klib/tipmanager.h b/src/klib/tipmanager.h
index 5224818..d9fda2c 100644
--- a/src/klib/tipmanager.h
+++ b/src/klib/tipmanager.h
@@ -53,7 +53,7 @@ class LIB_EXPORT TipManager : public QObject
friend class ResizeEventFilter;
public:
//Constructor
- TipManager(QTreeView* parent, const QString& path, const QString& text, int \
maxLine); + TipManager(QTreeView* parent);
//Getter
QImage getImage();
@@ -61,14 +61,12 @@ public:
//Setters
void setTopMargin(int margin);
void setBottomMargin(int margin);
- void setCurrentTip(bool tip);
-
- //Helper
-// static QStringList stringToLineArray(const QFont& font, QString text, int \
width = -1); + void setCurrentTip(Tip* tip);
private:
//Methods
void reload();
+ void setCurrentTip_private(Tip* tip);
//Attributes
QPalette m_OriginalPalette;
@@ -76,14 +74,15 @@ private:
int m_TopMargin ;
int m_BottomMargin ;
QImage m_CurrentImage ;
- Tip m_Tip ;
- bool m_pCurrentTip ;
+ Tip* m_pCurrentTip ;
TipAnimationWrapper m_pAnim ;
FrameDescription m_CurrentFrame ;
+ QList<Tip*> m_lTipQueue ;
private slots:
void animationStep(FrameDescription desc);
void changeSize(bool ignoreAnim = false);
+ void animationEnded();
signals:
void sizeChanged(QRect newRect,bool ignoreAnim);
diff --git a/src/widgets/tips/dialpadtip.cpp b/src/widgets/tips/dialpadtip.cpp
new file mode 100644
index 0000000..f858437
--- /dev/null
+++ b/src/widgets/tips/dialpadtip.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+ * Copyright (C) 2012 by Savoir-Faire Linux *
+ * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
+ * *
+ * 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 General Public License *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+#include "dialpadtip.h"
+
+//Qt
+#include <QtSvg/QSvgRenderer>
+#include <QtGui/QPainter>
+#include <QtGui/QFontMetrics>
+#include <QtCore/QFile>
+
+//KDE
+#include <KDebug>
+#include <KLocale>
+#include <KStandardDirs>
+
+///Constructor
+DialPadTip::DialPadTip(QWidget* parent) : Tip(parent,"",i18n("Use the dialpad below \
or start typing a number. Use the dialpad below or start typing a number. Use the \
dsadasdialpad below or start typing a number. Use thasdasde dialpad below or \
sasdasdtart typing a number. ")) +
+{
+ loadSvg(KStandardDirs::locate("data", "sflphone-client-kde/tips/keyboard.svg"));
+}
+
+///Destructor
+DialPadTip::~DialPadTip()
+{
+}
+
+QRect DialPadTip::getDecorationRect()
+{
+ return QRect(0,0,m_CurrentSize.width()-2*PADDING,60);
+}
+
+void DialPadTip::paintDecorations(QPainter& p, const QRect& textRect)
+{
+ if (!m_pR)
+ m_pR = new QSvgRenderer(m_OriginalFile);
+ m_pR->render(&p,QRect(m_CurrentRect.width() - PADDING - 50*2.59143327842 - 10 \
,textRect.y()+textRect.height() + 10,50*2.59143327842,50)); +}
diff --git a/src/widgets/tips/dialpadtip.h b/src/widgets/tips/dialpadtip.h
new file mode 100644
index 0000000..110a641
--- /dev/null
+++ b/src/widgets/tips/dialpadtip.h
@@ -0,0 +1,48 @@
+/****************************************************************************
+ * Copyright (C) 2012 by Savoir-Faire Linux *
+ * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
+ * *
+ * 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 General Public License *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+#ifndef TIP_DIALPAD_H
+#define TIP_DIALPAD_H
+//Base
+#include "../../klib/tip.h"
+
+//SFLPhone
+#include <QtCore/QStringList>
+#include <QtCore/QSize>
+#include <QtGui/QImage>
+#include <QtGui/QPalette>
+#include <QtGui/QWidget>
+
+class QSvgRenderer;
+
+//Qt
+class QPainter;
+
+///A tip to be passed to the TipLoader
+class DialPadTip : public Tip
+{
+ Q_OBJECT
+public:
+ DialPadTip(QWidget* parent = nullptr);
+ virtual ~DialPadTip();
+
+protected:
+ virtual QRect getDecorationRect();
+ virtual void paintDecorations(QPainter& p, const QRect& textRect);
+};
+
+#endif
\ No newline at end of file
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic