📄 qtguimainwindow.cpp
字号:
/** * Copyright (C) 2004-2005 Savoir-Faire Linux inc. * Author: Laurielle Lea <laurielle.lea@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. */#include "../../configurationtree.h"#include <stdio.h>#include <qbitmap.h>#include <qcheckbox.h>#include <qcombobox.h>#include <qevent.h>#include <qinputdialog.h>#include <qlineedit.h>#include <qmessagebox.h>#include <qpushbutton.h>#include <qregexp.h>#include <qsettings.h>#include <qspinbox.h>#include <qtimer.h>#include <qtooltip.h>#include "../../audio/audiodrivers.h"#include "../../configuration.h"#include "../../global.h"#include "../../manager.h"#include "../../user_cfg.h"#include "../../skin.h"#include "configurationpanel.h"#include "jpushbutton.h"#include "numerickeypadtools.h"#include "point.h"#include "phoneline.h"#include "qtGUImainwindow.h"#include "vector.h"#include "volumecontrol.h"#define QCHAR_TO_STRIP "-"#define REG_EXPR "(-|\\(|\\)| )" ///////////////////////////////////////////////////////////////////////////////// Tray Icon implementation///////////////////////////////////////////////////////////////////////////////MyTrayIcon::MyTrayIcon(const QPixmap &icon, const QString &tooltip, QPopupMenu *_mypop, QObject *parent, const char *name) : TrayIcon (icon, tooltip, _mypop, parent, name){ menu = _mypop;}voidMyTrayIcon::mousePressEvent (QMouseEvent *e) { switch ( e->button() ) { case RightButton: menu->popup( e->globalPos() ); e->accept(); break; case LeftButton: emit clickedLeft(); break; case MidButton: break; default: break; }}///////////////////////////////////////////////////////////////////////////////// QtGUIMainWindow implementation////////////////////////////////////////////////////////////////////////////////** * Default Constructor * Init, Connections */QtGUIMainWindow::QtGUIMainWindow (QWidget *parent, const char *name, WFlags f, Manager *mngr) : TransQWidget (parent, name, f), GuiFramework(mngr) { for (int i = 0; i < NUMBER_OF_LINES; i++) { phLines[i] = new PhoneLine(); phLines[i]->setState(FREE); _TabIncomingCalls[i] = -1; } // Create configuration_panel _panel = new ConfigurationPanel (0, 0, false); // URL input dialog _urlinput = new URL_Input (this); // For managing _callmanager = mngr; // For DTMF _key = new DTMF (); _buf = new float32[SIZEBUF]; // Create new display and numeric _keypad _lcd = new MyDisplay(this, 0, this); _keypad = new NumericKeypad (this, NULL, Qt::WDestructiveClose | Qt::WStyle_Customize | Qt::WStyle_NoBorder); _currentLine = -1; _chosenLine = -1; _prevLine = -1; _first = true; _chooseLine = false; _transfer = false; _dialtone = false; _msgVar = false; _apply = false; // Initialisation of all that concern the skin initSkin(); this->initBlinkTimer(); // By default, keyboard mapping mode is numerical mode this->setMode(NUM_MODE); // Move setMainLCD (); // Change window title and Icon. this->setCaption(PROGNAME); this->setIcon(QPixmap(Skin::getPathPixmap(QString(PIXDIR), QString(SFLPHONE_LOGO)))); // Show the GUI this->show(); // Handle the tray icon system _mypop = new QPopupMenu(this); _mypop->insertItem ("Quit", qApp, SLOT(quit())); _trayicon = new MyTrayIcon(QPixmap( Skin::getPathPixmap(QString(PIXDIR), QString(TRAY_ICON))), NULL, _mypop, parent, name); _trayicon->show(); // Connect to handle _trayicon connect(_trayicon, SIGNAL(clickedLeft()), this, SLOT(clickHandle())); // Connect _blinkTimer signals to blink slot connect(_blinkTimer, SIGNAL(timeout()),this, SLOT(blinkMessageSlot())); connect (_blinkTimer, SIGNAL(timeout()), this, SLOT(blinkRingSlot()) ); connect (_blinkTimer, SIGNAL(timeout()), this, SLOT(blinkLineSlot())); // Connect to append url in display connect (_urlinput->buttonOK, SIGNAL(clicked()), this, SLOT(stripSlot())); // Connect to save settings connect (_panel->buttonSave, SIGNAL(clicked()), this, SLOT(save())); // Connect to apply skin connect (_panel->buttonApplySkin, SIGNAL(clicked()), this,SLOT(applySkin())); // Connect to register manually connect (_panel->Register, SIGNAL(clicked()), this, SLOT(registerSlot()));}/** * Destructor */QtGUIMainWindow::~QtGUIMainWindow(void) { deleteButtons(); delete _panel; delete _blinkTimer; delete _keypad; delete _lcd; delete _urlinput; delete _callmanager; delete _mypop; delete _trayicon; delete pt; delete _key; delete[] _buf; delete[] phLines;}voidQtGUIMainWindow::deleteButtons (void) { delete phoneKey_transf; delete phoneKey_msg; delete phoneKey_conf; delete phoneKey_line0; delete phoneKey_line1; delete phoneKey_line2; delete phoneKey_line3; delete reduce_button; delete quit_button; delete addr_book_button; delete configuration_button; delete hangup_button; delete dial_button; delete mute_button; delete dtmf_button; delete vol_mic; delete vol_spkr; delete micVolVector; delete spkrVolVector; for (int j = 0; j < NUMBER_OF_LINES; j++) { delete phLines[j]->button(); }}///////////////////////////////////////////////////////////////////////////////// Private Methods implementations ////////////////////////////////////////////////////////////////////////////////** * Init and start blink timer for all blinking pixmap, with 500 ms timeout. */voidQtGUIMainWindow::initBlinkTimer(void) { _blinkTimer = new QTimer(this); _blinkTimer->start(500);}/** * Init variable with skin choice */QStringQtGUIMainWindow::setPathSkin (void) { return QString(Config::getchar( "Preferences", "Themes.skinChoice", "metal"));}/** * Init variable with ring choice */stringQtGUIMainWindow::ringFile(void) { return get_config_fields_str(AUDIO, RING_CHOICE);}/** * Get whole path for rings */stringQtGUIMainWindow::getRingtoneFile (void) { string ringFilename(Skin::getPathRing(string(RINGDIR), ringFile())); return ringFilename;}voidQtGUIMainWindow::initSkin (void) { // Load file configuration skin string skinfilename(Skin::getPath(QString(SKINDIR), setPathSkin(), QString(FILE_INI))); if (!_apply) { this->pt = new Point(skinfilename); } else { // If click on apply button delete pt; deleteButtons(); this->pt = new Point(skinfilename); } // Initialisation of the buttons initSpkrVolumePosition(); initMicVolumePosition(); initButtons(); initVolume(); // Connections of the buttons connections(); // Load background image phone setbgPixmap (new QPixmap (Skin::getPath(QString(SKINDIR), setPathSkin(), QString(PIXMAP_PHONE)))); // Transform pixmap to QImage setSourceImage (); this->setMaximumSize (getSourceImage().width(), getSourceImage().height()); this->setGeometry (MAIN_INITIAL_POSITION, MAIN_INITIAL_POSITION, getSourceImage().width(), getSourceImage().height()); // Calculate just one time the transparency mask bit to bit transparencyMask (); // Line pixmaps initialisation for (int i = 0; i < NUMBER_OF_LINES; i++) { for (int j = 0; j < NUMBER_OF_STATES; j++) { TabLinePixmap[i][j] = QPixmap(Skin::getPath(QString(SKINDIR), setPathSkin(), QString(PIXMAP_LINE(i, j)))); } } // Message pixmaps initialisation TabMsgPixmap[0] = QPixmap(Skin::getPath(QString(SKINDIR), setPathSkin(), PIXMAP_MESSAGE_OFF)); TabMsgPixmap[1] = QPixmap(Skin::getPath(QString(SKINDIR), setPathSkin(), PIXMAP_MESSAGE_ON));}voidQtGUIMainWindow::initSpkrVolumePosition (void) { if (pt->getDirection(VOL_SPKR) == VERTICAL) { vol_spkr_x = Config::get("Audio", "Volume.speakers_x", pt->getX(VOL_SPKR)); vol_spkr_y = Config::get("Audio", "Volume.speakers_y", pt->getVariation(VOL_SPKR)); } else if (pt->getDirection(VOL_SPKR) == HORIZONTAL) { vol_spkr_x = Config::get("Audio", "Volume.speakers_x", pt->getX(VOL_SPKR) + pt->getVariation(VOL_SPKR)); vol_spkr_y = Config::get("Audio", "Volume.speakers_y", pt->getY(VOL_SPKR)); }} voidQtGUIMainWindow::initMicVolumePosition (void) { if (pt->getDirection(VOL_MIC) == VERTICAL) { vol_mic_x = Config::get("Audio", "Volume.micro_x", pt->getX(VOL_MIC)); vol_mic_y = Config::get("Audio", "Volume.micro_y", pt->getVariation(VOL_MIC)); } else if (pt->getDirection(VOL_MIC) == HORIZONTAL) { vol_mic_x = Config::get("Audio", "Volume.micro_x", pt->getX(VOL_MIC) + pt->getVariation(VOL_MIC)); vol_mic_y = Config::get("Audio", "Volume.micro_y", pt->getY(VOL_MIC)); }}voidQtGUIMainWindow::initVolume (void) { _callmanager->setSpkrVolume(spkrVolVector->Y() - vol_spkr_y); _callmanager->setMicroVolume(micVolVector->Y() - vol_mic_y);}/** * Inits all phonekey buttons. * Create new QPushButtons, set up tool tip, disable focus, set button geometry * set palette. */voidQtGUIMainWindow::initButtons (void) { // Buttons initialisation phoneKey_msg= new JPushButton(this, NULL, VOICEMAIL); phoneKey_transf = new JPushButton(this, NULL, TRANSFER); phoneKey_conf = new JPushButton(this, NULL, CONFERENCE); reduce_button = new JPushButton(this, NULL, MINIMIZE); quit_button = new JPushButton(this, NULL, CLOSE); addr_book_button = new JPushButton(this, NULL, DIRECTORY); configuration_button = new JPushButton(this, NULL, SETUP); hangup_button = new JPushButton(this, NULL, HANGUP); dial_button = new JPushButton(this, NULL, CONNECT); mute_button = new JPushButton(this, NULL, MUTE); dtmf_button = new JPushButton(this, NULL, DTMF_SHOW); // Set tooltip buttons QToolTip::add(reduce_button, tr("Minimize window")); QToolTip::add(quit_button, tr("Close window (Ctrl+Q)")); QToolTip::add(phoneKey_msg, tr("Get your message")); QToolTip::add(phoneKey_transf, tr("Call transfer")); QToolTip::add(phoneKey_conf, tr("Conference")); QToolTip::add(addr_book_button, tr("Address book")); QToolTip::add(configuration_button, tr("Configuration tools (Ctrl+C)")); QToolTip::add(hangup_button, tr("Hangup")); QToolTip::add(dial_button, tr("Dial")); QToolTip::add(mute_button, tr("Mute")); QToolTip::add(dtmf_button, tr("Show DTMF _keypad (Ctrl+D)")); // Buttons position phoneKey_msg->move (pt->getX(VOICEMAIL), pt->getY(VOICEMAIL)); phoneKey_transf->move (pt->getX(TRANSFER), pt->getY(TRANSFER)); phoneKey_conf->move (pt->getX(CONFERENCE), pt->getY(CONFERENCE)); reduce_button->move (pt->getX(MINIMIZE), pt->getY(MINIMIZE)); addr_book_button->move (pt->getX(DIRECTORY), pt->getY(DIRECTORY)); quit_button->move (pt->getX(CLOSE), pt->getY(CLOSE)); configuration_button->move (pt->getX(SETUP), pt->getY(SETUP)); hangup_button->move (pt->getX(HANGUP), pt->getY(HANGUP)); dial_button->move (pt->getX(CONNECT), pt->getY(CONNECT)); mute_button->move (pt->getX(MUTE), pt->getY(MUTE)); dtmf_button->move (pt->getX(DTMF_SHOW), pt->getY(DTMF_SHOW)); // Loop for line buttons // Initialisation, set no focus, set geometry, set palette, pixmap for (int j = 0; j < NUMBER_OF_LINES; j++) { QString lnum; lnum = "l" + lnum.setNum (j + 1); phLines[j]->setButton(new JPushButton( this, NULL, lnum.ascii())); phLines[j]->button()->move (pt->getX(lnum),pt->getY(lnum)); } // Set pixmaps volume micVolVector = new Vector(this, VOL_MIC, pt); spkrVolVector = new Vector(this, VOL_SPKR, pt); vol_mic = new VolumeControl(this, NULL, VOLUME, micVolVector); vol_spkr = new VolumeControl(this, NULL, VOLUME, spkrVolVector); vol_mic->move(vol_mic_x, vol_mic_y); vol_spkr->move(vol_spkr_x, vol_spkr_y);}voidQtGUIMainWindow::connections (void) { // Connect for clicked numeric _keypad button connect ((QObject*)_keypad->key0, SIGNAL(clicked()), this, SLOT(pressedKey0())); connect ((QObject*)_keypad->key1, SIGNAL(clicked()), this, SLOT(pressedKey1())); connect ((QObject*)_keypad->key2, SIGNAL(clicked()), this, SLOT(pressedKey2())); connect ((QObject*)_keypad->key3, SIGNAL(clicked()), this, SLOT(pressedKey3())); connect ((QObject*)_keypad->key4, SIGNAL(clicked()), this, SLOT(pressedKey4())); connect ((QObject*)_keypad->key5, SIGNAL(clicked()), this, SLOT(pressedKey5())); connect ((QObject*)_keypad->key6, SIGNAL(clicked()), this, SLOT(pressedKey6())); connect ((QObject*)_keypad->key7, SIGNAL(clicked()), this, SLOT(pressedKey7())); connect ((QObject*)_keypad->key8, SIGNAL(clicked()), this, SLOT(pressedKey8())); connect ((QObject*)_keypad->key9, SIGNAL(clicked()), this, SLOT(pressedKey9())); connect ((QObject*)_keypad->keyStar, SIGNAL(clicked()), this, SLOT(pressedKeyStar())); connect ((QObject*)_keypad->keyHash, SIGNAL(clicked()), this, SLOT(pressedKeyHash())); connect ((QObject*)_keypad->keyClose, SIGNAL(clicked()), this, SLOT(dtmfKeypad())); // Connections for the lines connect (phLines[0]->button(), SIGNAL(clicked()), this, SLOT(button_line0())); connect (phLines[1]->button(), SIGNAL(clicked()), this, SLOT(button_line1())); connect (phLines[2]->button(), SIGNAL(clicked()), this, SLOT(button_line2())); connect (phLines[3]->button(), SIGNAL(clicked()), this, SLOT(button_line3())); connect (phLines[4]->button(), SIGNAL(clicked()), this, SLOT(button_line4())); connect (phLines[5]->button(), SIGNAL(clicked()), this, SLOT(button_line5())); // Misc connect (phoneKey_msg, SIGNAL(clicked()), this, SLOT(button_msg())); connect (phoneKey_transf, SIGNAL(clicked()), this, SLOT(button_transfer())); connect (phoneKey_conf, SIGNAL(clicked()), this, SLOT(button_conf())); connect (dial_button, SIGNAL(clicked()), this, SLOT(dial())); connect (mute_button, SIGNAL(clicked()), this, SLOT(button_mute())); connect (hangup_button, SIGNAL(clicked()), this, SLOT(hangupLine())); connect (configuration_button,SIGNAL(clicked()),this,SLOT(configuration())); connect (addr_book_button, SIGNAL(clicked()), this,SLOT(addressBook())); connect (dtmf_button, SIGNAL(clicked()), this, SLOT(dtmfKeypad())); // Connect to reduce connect (reduce_button, SIGNAL(clicked()), this, SLOT(reduceHandle())); // Connect to quit with keyboard connect (this, SIGNAL(keyPressed(int)), this, SLOT(qt_quitApplication())); // Connect to quit with quit button connect (quit_button, SIGNAL(clicked()), this, SLOT(qt_quitApplication())); // Connections for volume control connect(vol_spkr, SIGNAL(setVolumeValue(int)), this, SLOT(volumeSpkrChanged(int))); connect(vol_mic, SIGNAL(setVolumeValue(int)), this, SLOT(volumeMicChanged(int)));}/** * Returns true if the keyboard mapping returns letters. * * @return bool */boolQtGUIMainWindow::isInTextMode (void) { if (modeType == TEXT_MODE) { return true; } else { return false; }}/** * Returns true if the keyboard mapping returns digits. * * @return bool */boolQtGUIMainWindow::isInNumMode (void) { if (modeType == NUM_MODE) { return true; } else { return false; }}/** * Sets up the keyboard mapping mode. */voidQtGUIMainWindow::setMode (int mode) { this->modeType = mode;}short QtGUIMainWindow::isThereIncomingCall (void){ for (int i = 0; i < NUMBER_OF_LINES; i++) { if (_TabIncomingCalls[i] > 0) { return _TabIncomingCalls[i]; } } return -1;}short QtGUIMainWindow::isIncomingCall (int line){ if (_TabIncomingCalls[line] > 0) { return _TabIncomingCalls[line]; } else { return -1; }}intQtGUIMainWindow::id2line (short id){ int i; for (i = 0; i < NUMBER_OF_LINES; i++) { if (phLines[i]->getCallId() == id) { return i; } } if (i == NUMBER_OF_LINES) { _debug("Id is not attributed to a phoneline\n"); return -1; } return -1;}shortQtGUIMainWindow::line2id (int line){ short i; if (line != -1) { i = phLines[line]->getCallId(); } else { return -1; } if (i > 0) { return i; } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -