mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
We have a scrolling LCD
This commit is contained in:
@ -32,7 +32,8 @@
|
||||
* This class Emulate a PushButton but takes two
|
||||
* images to display its state.
|
||||
*/
|
||||
class JPushButton : public QLabel {
|
||||
class JPushButton : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -10,6 +10,7 @@ PhoneLine::PhoneLine(const Session &session,
|
||||
, mCall(NULL)
|
||||
, mLine(line)
|
||||
, mSelected(false)
|
||||
, mLineStatus("test")
|
||||
{}
|
||||
|
||||
PhoneLine::~PhoneLine()
|
||||
@ -18,6 +19,12 @@ PhoneLine::~PhoneLine()
|
||||
mCall = NULL;
|
||||
}
|
||||
|
||||
std::string
|
||||
PhoneLine::getLineStatus()
|
||||
{
|
||||
return mLineStatus;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
PhoneLine::line()
|
||||
{
|
||||
|
@ -52,6 +52,8 @@ public:
|
||||
{return !mCall;}
|
||||
|
||||
void sendKey(Qt::Key c);
|
||||
|
||||
std::string getLineStatus();
|
||||
|
||||
public slots:
|
||||
void incomming(const Call &call);
|
||||
@ -96,4 +98,6 @@ private:
|
||||
bool mInUse;
|
||||
//This is the buffer when the line is not in use;
|
||||
std::string mBuffer;
|
||||
|
||||
std::string mLineStatus;
|
||||
};
|
||||
|
@ -64,6 +64,7 @@ PhoneLineManagerImpl::start()
|
||||
{
|
||||
isInitialized();
|
||||
|
||||
emit globalStatusSet(QString(tr("Trying to connect to sflphone server..")));
|
||||
mSession->connect();
|
||||
}
|
||||
|
||||
@ -78,6 +79,9 @@ void PhoneLineManagerImpl::isInitialized()
|
||||
void
|
||||
PhoneLineManagerImpl::connect()
|
||||
{
|
||||
isInitialized();
|
||||
|
||||
emit globalStatusSet(QString(tr("Trying to connect to sflphone server..")));
|
||||
mSession->connect();
|
||||
}
|
||||
|
||||
@ -86,6 +90,7 @@ PhoneLineManagerImpl::startSession()
|
||||
{
|
||||
isInitialized();
|
||||
|
||||
emit globalStatusSet(QString(tr("Trying to get line status...")));
|
||||
mSession->getCallStatus();
|
||||
}
|
||||
|
||||
@ -94,6 +99,7 @@ PhoneLineManagerImpl::handleEvents()
|
||||
{
|
||||
isInitialized();
|
||||
|
||||
emit globalStatusSet(QString(tr("SFLPhone is ready to serve you, master.")));
|
||||
mSession->getEvents();
|
||||
}
|
||||
|
||||
@ -188,6 +194,7 @@ PhoneLineManagerImpl::selectNextAvailableLine()
|
||||
// We don't need to lock it, since it is
|
||||
// done at the top.
|
||||
selectedLine->select();
|
||||
emit lineStatusSet(QString::fromStdString(selectedLine->getLineStatus()));
|
||||
}
|
||||
|
||||
return selectedLine;
|
||||
@ -311,6 +318,7 @@ PhoneLineManagerImpl::selectLine(unsigned int line, bool hardselect)
|
||||
|
||||
PhoneLineLocker guard(selectedLine);
|
||||
selectedLine->select(hardselect);
|
||||
emit lineStatusSet(QString::fromStdString(selectedLine->getLineStatus()));
|
||||
if(selectedLine->isAvailable()) {
|
||||
mSession->playTone();
|
||||
}
|
||||
|
@ -50,6 +50,8 @@ signals:
|
||||
void readyToSendStatus();
|
||||
void readyToHandleEvents();
|
||||
void gotErrorOnCallStatus();
|
||||
void globalStatusSet(const QString &);
|
||||
void lineStatusSet(const QString &);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
|
175
src/gui/official/SFLLcd.cpp
Normal file
175
src/gui/official/SFLLcd.cpp
Normal file
@ -0,0 +1,175 @@
|
||||
#include <QDateTime>
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
|
||||
#include "globals.h"
|
||||
#include "JPushButton.hpp"
|
||||
#include "SFLLcd.hpp"
|
||||
|
||||
#define FONT_FAMILY "Courier"
|
||||
// Others fixed font support "Monospace", "Fixed", "MiscFixed"
|
||||
#define FONT_SIZE 10
|
||||
|
||||
SFLLcd::SFLLcd(QWidget *parent, Qt::WFlags flags)
|
||||
: QLabel(parent, flags)
|
||||
, mScreen(":/sflphone/images/screen_main")
|
||||
, mOverscreen(JPushButton::transparize(":/sflphone/images/overscreen.png"))
|
||||
, mGlobalStatusPos(-1)
|
||||
, mLineStatusPos(-1)
|
||||
, mIsTimed(false)
|
||||
, mFont(FONT_FAMILY, FONT_SIZE)
|
||||
{
|
||||
mFont.setBold(true);
|
||||
|
||||
setPixmap(mScreen);
|
||||
resize(mScreen.size());
|
||||
move(22,44);
|
||||
|
||||
|
||||
mTimer = new QTimer(this);
|
||||
QObject::connect(mTimer, SIGNAL(timeout()),
|
||||
this, SLOT(updateText()));
|
||||
QObject::connect(mTimer, SIGNAL(timeout()),
|
||||
this, SLOT(update()));
|
||||
mTimer->start(100);
|
||||
}
|
||||
|
||||
void
|
||||
SFLLcd::updateText()
|
||||
{
|
||||
if(mGlobalStatusPos >= 0) {
|
||||
mGlobalStatusPos++;
|
||||
}
|
||||
|
||||
if(mLineStatusPos >= 0) {
|
||||
mLineStatusPos++;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SFLLcd::startTiming()
|
||||
{
|
||||
mIsTimed = true;
|
||||
mTime.start();
|
||||
}
|
||||
|
||||
void
|
||||
SFLLcd::stopTiming()
|
||||
{
|
||||
mIsTimed = false;
|
||||
}
|
||||
|
||||
void
|
||||
SFLLcd::setGlobalStatus(const QString &global)
|
||||
{
|
||||
if(textIsTooBig(global)) {
|
||||
mGlobalStatusPos = 0;
|
||||
}
|
||||
else {
|
||||
mGlobalStatusPos = -1;
|
||||
}
|
||||
mGlobalStatus = global;
|
||||
}
|
||||
|
||||
void
|
||||
SFLLcd::setLineStatus(const QString &line)
|
||||
{
|
||||
if(textIsTooBig(line)) {
|
||||
mGlobalStatusPos = 0;
|
||||
}
|
||||
else {
|
||||
mLineStatusPos = -1;
|
||||
}
|
||||
mLineStatus = line;
|
||||
}
|
||||
|
||||
QString
|
||||
SFLLcd::getTimeStatus()
|
||||
{
|
||||
if(mIsTimed) {
|
||||
int seconds = mTime.elapsed() / 1000 ;
|
||||
return QTime(seconds / 60 / 60, seconds / 60, seconds % 60).toString("hh:mm:ss");
|
||||
}
|
||||
else {
|
||||
QTime t(QTime::currentTime());
|
||||
QString s;
|
||||
if(t.second() % 2) {
|
||||
s = t.toString("hh:mm");
|
||||
}
|
||||
else {
|
||||
s = t.toString("hh mm");
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SFLLcd::paintEvent(QPaintEvent *)
|
||||
{
|
||||
// Painter settings
|
||||
QFontMetrics fm(mFont);
|
||||
|
||||
int margin = 2;
|
||||
|
||||
QPainter p(this);
|
||||
p.setFont(mFont);
|
||||
p.drawPixmap(0,0, mScreen);
|
||||
p.drawText(QPoint(margin, fm.height()),
|
||||
extractVisibleText(mGlobalStatus, mGlobalStatusPos));
|
||||
p.drawText(QPoint(margin, 2*fm.height()),
|
||||
extractVisibleText(mLineStatus, mLineStatusPos));
|
||||
|
||||
p.drawText(QPoint(margin, mScreen.size().height() - margin), getTimeStatus());
|
||||
p.drawPixmap(0,0, mOverscreen);
|
||||
p.end();
|
||||
}
|
||||
|
||||
bool
|
||||
SFLLcd::textIsTooBig(const QString &text)
|
||||
{
|
||||
QFontMetrics fm(mFont);
|
||||
|
||||
int screenWidth = mScreen.width() - 4;
|
||||
int textWidth = fm.boundingRect(text).width();
|
||||
|
||||
if(textWidth > screenWidth) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QString
|
||||
SFLLcd::extractVisibleText(const QString &text, int &pos)
|
||||
{
|
||||
QFontMetrics fm(mFont);
|
||||
QString tmp(text);
|
||||
|
||||
int nbCharBetween = 8;
|
||||
|
||||
if(pos >= tmp.size() + nbCharBetween) {
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
// Chop the text until it's not too big
|
||||
if(textIsTooBig(tmp)) {
|
||||
// We add automatiquely the space the the text again at
|
||||
// the end.
|
||||
tmp += QString().fill(QChar(' '), nbCharBetween);
|
||||
tmp += text;
|
||||
|
||||
if(pos == -1) {
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
tmp.remove(0, pos);
|
||||
while(textIsTooBig(tmp)) {
|
||||
tmp.chop(1);
|
||||
}
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
68
src/gui/official/SFLLcd.hpp
Normal file
68
src/gui/official/SFLLcd.hpp
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
|
||||
* Author: Jean-Philippe Barrette-LaPierre
|
||||
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SFLLCD_HPP__
|
||||
#define __SFLLCD_HPP__
|
||||
|
||||
#include <QLabel>
|
||||
#include <QObject>
|
||||
#include <QPixmap>
|
||||
#include <QTime>
|
||||
#include <QTimer>
|
||||
|
||||
class SFLLcd : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SFLLcd(QWidget *parent = NULL, Qt::WFlags flags = 0);
|
||||
|
||||
bool textIsTooBig(const QString &text);
|
||||
|
||||
public slots:
|
||||
virtual void paintEvent(QPaintEvent *event);
|
||||
QString getTimeStatus();
|
||||
|
||||
void setGlobalStatus(const QString &global);
|
||||
void setLineStatus(const QString &line);
|
||||
|
||||
void startTiming();
|
||||
void stopTiming();
|
||||
void updateText();
|
||||
QString extractVisibleText(const QString &text, int &pos);
|
||||
|
||||
private:
|
||||
QPixmap mScreen;
|
||||
QPixmap mOverscreen;
|
||||
|
||||
QString mGlobalStatus;
|
||||
QString mLineStatus;
|
||||
int mGlobalStatusPos;
|
||||
int mLineStatusPos;
|
||||
|
||||
bool mIsTimed;
|
||||
QTime mTime;
|
||||
QTimer *mTimer;
|
||||
QTimer *mTextTimer;
|
||||
|
||||
QFont mFont;
|
||||
};
|
||||
|
||||
#endif
|
@ -4,6 +4,7 @@
|
||||
#include "PhoneLineButton.hpp"
|
||||
#include "Requester.hpp"
|
||||
#include "SessionIOFactory.hpp"
|
||||
#include "SFLLcd.hpp"
|
||||
#include "SFLPhoneApp.hpp"
|
||||
#include "SFLPhoneWindow.hpp"
|
||||
#include "SFLRequest.hpp"
|
||||
@ -30,7 +31,6 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv)
|
||||
Requester::instance().registerObject< CallRelatedRequest >(std::string("hold"));
|
||||
Requester::instance().registerObject< CallRelatedRequest >(std::string("unhold"));
|
||||
Requester::instance().registerObject< CallRelatedRequest >(std::string("hangup"));
|
||||
PhoneLineManager::instance().start();
|
||||
}
|
||||
|
||||
void
|
||||
@ -64,6 +64,16 @@ SFLPhoneApp::initConnections(SFLPhoneWindow *w)
|
||||
&PhoneLineManager::instance(), SLOT(clear()));
|
||||
QObject::connect(w, SIGNAL(keyPressed(Qt::Key)),
|
||||
&PhoneLineManager::instance(), SLOT(sendKey(Qt::Key)));
|
||||
|
||||
// LCD Connections.
|
||||
QObject::connect(&PhoneLineManager::instance(), SIGNAL(lineStatusSet(const QString &)),
|
||||
w->mLcd, SLOT(setLineStatus(const QString &)));
|
||||
QObject::connect(&PhoneLineManager::instance(), SIGNAL(globalStatusSet(const QString &)),
|
||||
w->mLcd, SLOT(setGlobalStatus(const QString &)));
|
||||
|
||||
|
||||
|
||||
|
||||
QObject::connect(&PhoneLineManager::instance(), SIGNAL(disconnected()),
|
||||
w, SLOT(askReconnect()));
|
||||
QObject::connect(w, SIGNAL(reconnectAsked()),
|
||||
@ -74,5 +84,6 @@ SFLPhoneApp::initConnections(SFLPhoneWindow *w)
|
||||
QObject::connect(w, SIGNAL(resendStatusAsked()),
|
||||
&PhoneLineManager::instance(), SIGNAL(readyToSendStatus()));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,9 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "globals.h"
|
||||
#include "PhoneLineButton.hpp"
|
||||
#include "JPushButton.hpp"
|
||||
#include "PhoneLineButton.hpp"
|
||||
#include "SFLLcd.hpp"
|
||||
|
||||
SFLPhoneWindow::SFLPhoneWindow()
|
||||
: QMainWindow(NULL, Qt::FramelessWindowHint)
|
||||
@ -32,20 +33,22 @@ SFLPhoneWindow::SFLPhoneWindow()
|
||||
|
||||
mLastPos = pos();
|
||||
|
||||
// QLabel *os = new QLabel(this);
|
||||
// QPixmap overscreen(":/images/overscreen.png");
|
||||
// os->setPixmap(overscreen);
|
||||
// os->resize(overscreen.size());
|
||||
// os->move(22,44);
|
||||
|
||||
initGUIButtons();
|
||||
initWindowButtons();
|
||||
initLineButtons();
|
||||
initLCD();
|
||||
}
|
||||
|
||||
SFLPhoneWindow::~SFLPhoneWindow()
|
||||
{}
|
||||
|
||||
void
|
||||
SFLPhoneWindow::initLCD()
|
||||
{
|
||||
mLcd = new SFLLcd(this);
|
||||
mLcd->show();
|
||||
}
|
||||
|
||||
void
|
||||
SFLPhoneWindow::initGUIButtons()
|
||||
{
|
||||
|
@ -3,8 +3,9 @@
|
||||
#include <QPoint>
|
||||
#include <list>
|
||||
|
||||
class PhoneLineButton;
|
||||
class JPushButton;
|
||||
class PhoneLineButton;
|
||||
class SFLLcd;
|
||||
|
||||
class SFLPhoneWindow : public QMainWindow
|
||||
{
|
||||
@ -17,6 +18,7 @@ public:
|
||||
~SFLPhoneWindow();
|
||||
|
||||
private:
|
||||
void initLCD();
|
||||
void initGUIButtons();
|
||||
void initLineButtons();
|
||||
void initWindowButtons();
|
||||
@ -56,5 +58,7 @@ private:
|
||||
JPushButton *mOk;
|
||||
JPushButton *mClear;
|
||||
|
||||
SFLLcd *mLcd;
|
||||
|
||||
QPoint mLastPos;
|
||||
};
|
||||
|
@ -32,5 +32,6 @@ int main(int argc, char **argv)
|
||||
SFLPhoneWindow sfl;
|
||||
app.initConnections(&sfl);
|
||||
sfl.show();
|
||||
PhoneLineManager::instance().start();
|
||||
return app.exec();
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ HEADERS += Account.hpp \
|
||||
SessionIO.hpp \
|
||||
SessionIOFactory.hpp \
|
||||
SFLEvents.hpp \
|
||||
SFLLcd.hpp \
|
||||
SFLPhoneApp.hpp \
|
||||
SFLPhoneWindow.hpp \
|
||||
SFLRequest.hpp \
|
||||
@ -42,7 +43,6 @@ HEADERS += Account.hpp \
|
||||
ObjectFactory.inl \
|
||||
RequesterImpl.inl \
|
||||
ObjectPool.inl
|
||||
FORMS += SFLPhoneWindow.ui
|
||||
SOURCES += Account.cpp \
|
||||
Call.cpp \
|
||||
CallStatus.cpp \
|
||||
@ -57,6 +57,7 @@ SOURCES += Account.cpp \
|
||||
RequesterImpl.cpp \
|
||||
Session.cpp \
|
||||
SFLEvents.cpp \
|
||||
SFLLcd.cpp \
|
||||
SFLPhoneApp.cpp \
|
||||
SFLPhoneWindow.cpp \
|
||||
SFLRequest.cpp \
|
||||
|
@ -29,5 +29,6 @@
|
||||
<file>images/ok_off.png</file>
|
||||
<file>images/ok_on.png</file>
|
||||
<file>images/overscreen.png</file>
|
||||
<file>images/screen_main.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
Reference in New Issue
Block a user