00001
00002
00003
00004
00005
00006 #include <QThread>
00007 #include <QApplication>
00008 #include <QShowEvent>
00009 #include <QHideEvent>
00010
00011 #include "CConsole.h"
00012
00013
00014
00015
00016
00017
00018 CConsole::CConsole(QWidget *parent):QMainWindow(parent)
00019 {
00020 ui.setupUi(this);
00021 this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::WindowMinMaxButtonsHint);
00022
00023 rowNmb = 0;
00024
00025 pTimer = new QTimer(this);
00026 connect(pTimer,SIGNAL(timeout()),this,SLOT(update()));
00027
00028 pCreateThread = QThread::currentThread();
00029
00030 iconEnable = QIcon(QString::fromUtf8(":/VStudio/20x20/Check.png"));
00031 iconDisable = QIcon(QString::fromUtf8(":/VStudio/20x20/Disable.png"));
00032
00033
00034
00035
00036 consoleIsHidden = true;
00037 bOpenGlLog = false;
00038 bLogAll = ui.logAllCheckbox->isChecked();
00039 quality = ui.qualitySlider->value();
00040 q = 0;
00041 ui.actionOpenGL->setIcon(iconDisable);
00042 }
00043
00044
00045 CConsole::~CConsole()
00046 {
00047
00048 }
00049
00050
00051 void CConsole::SetLogStatus(int what,bool tf)
00052 {
00053 if(pCreateThread == QThread::currentThread()){
00054 switch(what){
00055 case LOG_OPENGL_ALL:
00056 bLogAll = true;
00057 ui.logAllCheckbox->setChecked(true);
00058 ui.qualitySlider->setDisabled(true);
00059 case LOG_OPENGL:
00060 bOpenGlLog = tf;
00061 if(!consoleIsHidden){
00062 statusChange(what,tf);
00063 }
00064 break;
00065 }
00066 }
00067 }
00068
00069
00070 void CConsole::Log(QString &text,int id)
00071 {
00072 if(pCreateThread == QThread::currentThread())
00073 {
00074 logQueueLocker.lock();
00075 QListWidgetItem *item = new QListWidgetItem(QString().setNum(rowNmb++),ui.listWidget);
00076 item->setData(Qt::DisplayRole,"Thread: " + QString().setNum(id) + " > "+text);
00077 ui.listWidget->scrollToBottom();
00078 logQueueLocker.unlock();
00079 }else{
00080 if(!consoleIsHidden)
00081 {
00082 if(bOpenGlLog)
00083 {
00084 if(bLogAll)
00085 {
00086 logQueueLocker.lock();
00087 logQueue.enqueue("Thread: " + QString().setNum(id) + " > " + text);
00088 logQueueLocker.unlock();
00089 }else{
00090 if(q-- < quality)
00091 {
00092 if(logQueueLocker.tryLock())
00093 {
00094 logQueue.enqueue("Thread: " + QString().setNum(id) + " > " + text);
00095 logQueueLocker.unlock();
00096 q = ui.qualitySlider->maximum();
00097 }
00098 }
00099 }
00100 }
00101 }
00102 }
00103 }
00104
00105
00106
00107
00108
00109
00110 void CConsole::statusChange(int what,bool tf)
00111 {
00112 switch(what){
00113 case LOG_OPENGL:
00114 if(bOpenGlLog){
00115 pTimer->start(60);
00116 ui.actionOpenGL->setIcon(iconDisable);
00117 }else{
00118 pTimer->stop();
00119 update();
00120 ui.actionOpenGL->setIcon(iconEnable);
00121 }
00122 break;
00123 }
00124 emit LogStatusChange(what,tf);
00125 }
00126
00127 void CConsole::update()
00128 {
00129 logQueueLocker.lock();
00130 while(!logQueue.isEmpty()){
00131
00132
00133 ui.listWidget->scrollToBottom();
00134 }
00135 logQueueLocker.unlock();
00136 }
00137
00138
00139
00140
00141
00142 void CConsole::hideEvent(QHideEvent *event){
00143 bool status = bOpenGlLog;
00144 SetLogStatus(LOG_OPENGL,false);
00145 bOpenGlLog = status;
00146 consoleIsHidden = true;
00147 event->accept();
00148 }
00149
00150 void CConsole::showEvent(QShowEvent *event){
00151 consoleIsHidden = false;
00152 SetLogStatus(LOG_OPENGL,bOpenGlLog);
00153 event->accept();
00154 }
00155
00156
00157
00158
00159
00160 void CConsole::on_actionOpenGL_triggered(){
00161 SetLogStatus(LOG_OPENGL,bOpenGlLog = !bOpenGlLog);
00162 ui.logAllCheckbox->setDisabled(!bOpenGlLog);
00163 }
00164
00165 void CConsole::on_actionClear_triggered(){
00166 logQueueLocker.lock();
00167 ui.listWidget->clear();
00168 logQueueLocker.unlock();
00169 }
00170
00171 void CConsole::on_actionSave_triggered(){
00172 logQueueLocker.lock();
00173
00174 logQueueLocker.unlock();
00175 }
00176
00177 void CConsole::on_logAllCheckbox_clicked(bool checked)
00178 {
00179 bLogAll = checked;
00180 ui.qualitySlider->setDisabled(checked);
00181 }
00182
00183 void CConsole::on_qualitySlider_valueChanged(int value)
00184 {
00185 quality = value;
00186 }