📄 mainwindow.cpp
字号:
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->settingsDialog = NULL;
this->mainWindowDraggable = false;
this->callRecordCounter = 0;
this->justDroppedForEdit = true;
this->setFocusPolicy(Qt::StrongFocus);
setupUi(this);
//this->centralwidget->setWindowOpacity(0.5); // Make it semi-transparent!
//QRegion myMask(0, 0, 100, 100);
//this->setMask(myMask);
//this->setWindowOpacity(0.5); // Make it semi-transparent!
QObject::connect(this->pushButton_Settings, SIGNAL(clicked()), this, SLOT(settings()));
//QObject::connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
QObject::connect(this->pushButton_DialAnsDrop, SIGNAL(clicked()), this, SLOT(dial_Ans_Drop()));
QObject::connect(this->pushButton_HoldResume, SIGNAL(clicked()), this, SLOT(hold_Resume()));
QObject::connect(this->pushButton_Credit, SIGNAL(clicked()), this, SLOT(credit()));
QObject::connect(this->pushButton_Number_0, SIGNAL(clicked()), this, SLOT(digit0Pressed()));
QObject::connect(this->pushButton_Number_1, SIGNAL(clicked()), this, SLOT(digit1Pressed()));
QObject::connect(this->pushButton_Number_2, SIGNAL(clicked()), this, SLOT(digit2Pressed()));
QObject::connect(this->pushButton_Number_3, SIGNAL(clicked()), this, SLOT(digit3Pressed()));
QObject::connect(this->pushButton_Number_4, SIGNAL(clicked()), this, SLOT(digit4Pressed()));
QObject::connect(this->pushButton_Number_5, SIGNAL(clicked()), this, SLOT(digit5Pressed()));
QObject::connect(this->pushButton_Number_6, SIGNAL(clicked()), this, SLOT(digit6Pressed()));
QObject::connect(this->pushButton_Number_7, SIGNAL(clicked()), this, SLOT(digit7Pressed()));
QObject::connect(this->pushButton_Number_8, SIGNAL(clicked()), this, SLOT(digit8Pressed()));
QObject::connect(this->pushButton_Number_9, SIGNAL(clicked()), this, SLOT(digit9Pressed()));
QObject::connect(this->pushButton_Number_Star, SIGNAL(clicked()), this, SLOT(digitStarPressed()));
QObject::connect(this->pushButton_Number_Pound, SIGNAL(clicked()), this, SLOT(digitPoundPressed()));
QObject::connect(this->pushButton_Minimize, SIGNAL(clicked()), this, SLOT(showMinimized ()));
QObject::connect(this->pushButton_Close, SIGNAL(clicked()), this, SLOT(close()));
QObject::connect(this->pushButton_CallRecord_Forward, SIGNAL(clicked()), this, SLOT(scrollCallRecord_Forward()));
QObject::connect(this->pushButton_CallRecord_Backward, SIGNAL(clicked()), this, SLOT(scrollCallRecord_Backward()));
QObject::connect(QCoreApplication::instance (), SIGNAL(aboutToQuit()), this, SLOT(stopTheMusic()));
QMetaObject::connectSlotsByName(this);
}
void MainWindow::displayRingRecordAt(int index)
{
if (!this->wrapper->isCallActive() )
{
if (!this->preferences->getCallRecords().isEmpty())
{
//this->statusbar->showMessage("Counter: " + QString::number(this->callRecordCounter));
int callRecsCount = this->preferences->getCallRecords().size();
if(index < 0)
{
// At the beginning of Call Record List!
this->callRecordCounter = 0;
this->pushButton_CallRecord_Backward->setEnabled(false);
}
else if(index >= callRecsCount)
{
// At the End of Call Record List!
this->callRecordCounter = callRecsCount-1;
this->pushButton_CallRecord_Forward->setEnabled(false);
}
else
{
// Somewhere inbetween!!
this->pushButton_CallRecord_Backward->setEnabled(true);
this->pushButton_CallRecord_Forward->setEnabled(true);
}
CallRecord* callRecord = this->preferences->getCallRecord(this->callRecordCounter);
this->label_TelNumber->setText(callRecord->getCallerIdNumber());
bool ok;
QDateTime aDateTime = QDateTime::currentDateTime();
aDateTime.setTime_t( callRecord->getCallStartTime().toUInt(&ok, 10) );
if(ok)
{
QString aDateTimeStr = aDateTime.toString(Qt::LocalDate);
this->label_TimerText->setText(" " + aDateTimeStr);
}
}
else
{
// No call records so do nothing!!!
}
}
else
{
//Still in an active call... ignore!
}
}
void MainWindow::digitPressed(char digit)// called by all digit buttons to send dtmf
{
if (!this->wrapper->isCallActive() )
{
// Not in any active call so you can edit numbers!
QString activeNumber = this->label_TelNumber->text();
if(this->justDroppedForEdit)
{
activeNumber = QString::fromUtf8("");
this->justDroppedForEdit = false;
}
activeNumber.append(digit);
this->label_TelNumber->setText(activeNumber);
}
else
{
/* else we send dtmf with the current call */
this->wrapper->send_dtmf(digit);
}
}
void MainWindow::keyEvent_deletePressed()
{
if (!this->wrapper->isCallActive() )
{
// Not in any active call so you can edit numbers!
QString activeNumber = this->label_TelNumber->text();
activeNumber.chop(1);
this->label_TelNumber->setText(activeNumber);
this->justDroppedForEdit = false;
}
}
void MainWindow::scrollCallRecord_Backward()
{
this->displayRingRecordAt(--this->callRecordCounter);
}
void MainWindow::scrollCallRecord_Forward()
{
this->displayRingRecordAt(++this->callRecordCounter);
}
void MainWindow::digit9Pressed() { this->digitPressed('9'); }
void MainWindow::digit8Pressed() { this->digitPressed('8'); }
void MainWindow::digit7Pressed() { this->digitPressed('7'); }
void MainWindow::digit6Pressed() { this->digitPressed('6'); }
void MainWindow::digit5Pressed() { this->digitPressed('5'); }
void MainWindow::digit4Pressed() { this->digitPressed('4'); }
void MainWindow::digit3Pressed() { this->digitPressed('3'); }
void MainWindow::digit2Pressed() { this->digitPressed('2'); }
void MainWindow::digit1Pressed() { this->digitPressed('1'); }
void MainWindow::digit0Pressed() { this->digitPressed('0'); }
void MainWindow::digitStarPressed() { this->digitPressed('*'); }
void MainWindow::digitPoundPressed() { this->digitPressed('#'); }
void MainWindow::keyPressEvent (QKeyEvent * event)
{
int keyPressed = event->key();
switch(keyPressed)
{
case Qt::Key_0: { this->pushButton_Number_0->click(); break;}
case Qt::Key_1: { this->pushButton_Number_1->click(); break;}
case Qt::Key_2: { this->pushButton_Number_2->click(); break;}
case Qt::Key_3: { this->pushButton_Number_3->click(); break;}
case Qt::Key_4: { this->pushButton_Number_4->click(); break;}
case Qt::Key_5: { this->pushButton_Number_5->click(); break;}
case Qt::Key_6: { this->pushButton_Number_6->click(); break;}
case Qt::Key_7: { this->pushButton_Number_7->click(); break;}
case Qt::Key_8: { this->pushButton_Number_8->click(); break;}
case Qt::Key_9: { this->pushButton_Number_9->click(); break;}
case Qt::Key_Asterisk: { this->pushButton_Number_Star->click(); break;}
case Qt::Key_NumberSign: { this->pushButton_Number_Pound->click(); break;}
case Qt::Key_Return: { }
case Qt::Key_Enter: { this->pushButton_DialAnsDrop->click(); break;}
case Qt::Key_Backspace: { }
case Qt::Key_Delete: { this->keyEvent_deletePressed(); break;}
case Qt::Key_Up: { this->pushButton_CallRecord_Backward->click(); break;}
case Qt::Key_Left: { this->pushButton_CallRecord_Backward->click(); break;}
case Qt::Key_Down: { this->pushButton_CallRecord_Forward->click(); break;}
case Qt::Key_Right: { this->pushButton_CallRecord_Forward->click(); break;}
//case Qt::Key_F1: { this->keyEvent_upPressed(); break;}
//case Qt::Key_F2: { this->keyEvent_downPressed(); break;}
default: { event->ignore(); break; }
}
}
void MainWindow::mouseMoveEvent ( QMouseEvent * event )
{
//QMessageBox::information(this, "Yakaphone", "mouseMoveEvent");
if(this->mainWindowDraggable)
{
this->move(event->globalX() - 100, event->globalY() - 50);
}
else
{
}
}
void MainWindow::mousePressEvent ( QMouseEvent * event )
{
//QMessageBox::information(this, "Yakaphone", "mousePressEvent");
//this->statusbar->showMessage(QString::number(event->x()) + " : " + QString::number(event->y()) );
int globalY = event->y();
if(globalY < 25)
{
this->mainWindowDraggable = true;
}
else
{
this->mainWindowDraggable = false;
}
}
void MainWindow::mouseReleaseEvent ( QMouseEvent * event )
{
//QMessageBox::information(this, "Yakaphone", "mouseReleaseEvent");
this->mainWindowDraggable = false;
}
void MainWindow::dial_Ans_Drop()
{
if (!this->wrapper->callSession.count()>0 || !(this->wrapper->callSession[this->wrapper->getSelectedCall()].isActive()) ) /* if we dont have any call then print the chars in the combobox */
{
QString activeNumber = this->label_TelNumber->text();
this->wrapper->dial(this->defaultAccount->accId, QString::fromUtf8(""), activeNumber);
}
else
{
if (this->wrapper->callSession[this->wrapper->getSelectedCall()].isOutgoing())
{ //if we are in a call then action is hangup
this->wrapper->interrupt_call();
}
else
{ // if we are receiving call then we are rejecting
this->wrapper->reject_call(this->wrapper->getSelectedCall());
}
}
}
void MainWindow::hold_Resume()
{
if (this->wrapper->callSession.count() > 0 )
{
QString isHold = this->wrapper->callSession[this->wrapper->getSelectedCall()].getCustomProperty(QString::fromUtf8("isHold"));
if(isHold == QString::fromUtf8("true"))
{
this->wrapper->resume_call(this->wrapper->getSelectedCall());
}
else
{
this->wrapper->hold_call(this->wrapper->getSelectedCall());
}
}
}
void MainWindow::credit()
{
this->wrapper->dial(this->defaultAccount->accId, QString::fromUtf8(""), CallRecord::mailBoxCallerIdNumber);
}
void MainWindow::settings()
{
if (this->settingsDialog == NULL)
{
this->settingsDialog = new SettingsDialog(this);
this->settingsDialog->setModal(true);
//Set the values to the current account values!!!
//QMessageBox::information(this, "Yakaphone", "setAccountSettings()");
this->settingsDialog->lineEdit_Username->setText(this->defaultAccount->username);
this->settingsDialog->lineEdit_Password->setText(this->defaultAccount->password);
this->settingsDialog->lineEdit_ServerName->setText(this->defaultAccount->iaxServer);
//QMessageBox::information(this, "Yakaphone", "setCodecSettings()");
this->settingsDialog->setCodecByName(this->defaultAccount->codec);
//QMessageBox::information(this, "Yakaphone", "setDeviceSettings()");
this->preferences->detectDevices();
QStringList outputDeviceNames = this->preferences->getOutputDeviceNames();
this->settingsDialog->comboBox_AudioOutput->addItems(outputDeviceNames);
this->settingsDialog->comboBox_AudioOutput->setCurrentIndex(this->preferences->getOutputDevice());
QStringList inputDeviceNames = this->preferences->getInputDeviceNames();
this->settingsDialog->comboBox_AudioInput->addItems(inputDeviceNames);
this->settingsDialog->comboBox_AudioInput->setCurrentIndex(this->preferences->getInputDevice());
QStringList ringDeviceNames = this->preferences->getRingDeviceNames();
this->settingsDialog->comboBox_AudioRing->addItems(ringDeviceNames);
this->settingsDialog->comboBox_AudioRing->setCurrentIndex(this->preferences->getRingDevice());
this->settingsDialog->checkBox_RingBuzzer->setChecked(this->preferences->getBuzzerRing());
//QMessageBox::information(this, "Yakaphone", "setFilterSettings()");
int filterFlag = this->preferences->getFilterFlag();
this->settingsDialog->checkBox_NoiseRecuction->setChecked(filterFlag & IAXC_FILTER_DENOISE);
this->settingsDialog->checkBox_AnalogAutomaticGainControl->setChecked(filterFlag & IAXC_FILTER_AAGC);
this->settingsDialog->checkBox_AutomaticGainControl->setChecked(filterFlag & IAXC_FILTER_AGC);
this->settingsDialog->checkBox_EchoCancellation->setChecked(filterFlag & IAXC_FILTER_ECHO);
this->settingsDialog->checkBox_ComfortNoise->setChecked(filterFlag & IAXC_FILTER_CN);
if(this->preferences->getSilenceThreshold() < 0)
{
this->settingsDialog->checkBox_SilenceSuppression->setChecked(false);
}
else
{
this->settingsDialog->checkBox_SilenceSuppression->setChecked(true);
}
//QMessageBox::information(this, "Yakaphone", "connect...");
QObject::connect(this->settingsDialog, SIGNAL(accepted()), this, SLOT(settingsAccepted()));
QObject::connect(this->settingsDialog, SIGNAL(rejected()), this, SLOT(settingsRejected()));
}
this->settingsDialog->exec();
}
void MainWindow::settingsAccepted()
{
// Store the set values of the account and save them!
this->defaultAccount->username = this->settingsDialog->lineEdit_Username->text();
this->defaultAccount->password = this->settingsDialog->lineEdit_Password->text();
this->defaultAccount->iaxServer = this->settingsDialog->lineEdit_ServerName->text();
this->defaultAccount->codec = this->settingsDialog->getSelectedCodecName();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -