12 #ifndef GSAFE_DISABLE_DEBUG
17 #ifndef DCONSOLE_NO_SQL
19 #endif // DCONSOLE_NO_SQL
21 #ifndef COMPILED_WITH_QT4X
23 #endif //COMPILED_WITH_QT4X
25 #endif //GSAFE_DISABLE_DEBUG
31 #ifndef GSAFE_DISABLE_DEBUG
33 #endif //GSAFE_DISABLE_DEBUG
35 #ifndef DCONSOLE_NO_SQL
38 #ifndef GSAFE_DISABLE_DEBUG
39 if(HDebugConsole::myself == NULL)
44 #endif //GSAFE_DISABLE_DEBUG
46 #endif // DCONSOLE_NO_SQL
50 #ifndef GSAFE_DISABLE_DEBUG
51 if(HDebugConsole::myself == NULL)
56 #endif //GSAFE_DISABLE_DEBUG
61 #ifndef GSAFE_DISABLE_DEBUG
62 if(HDebugConsole::myself == NULL)
67 #endif //GSAFE_DISABLE_DEBUG
72 #ifndef GSAFE_DISABLE_DEBUG
73 if(HDebugConsole::myself != NULL)
75 HDebugConsole::myself->close();
77 HDebugConsole::myself=NULL;
79 #endif //GSAFE_DISABLE_DEBUG
84 #ifndef GSAFE_DISABLE_DEBUG
85 QMessageBox::warning(NULL,t,txt);
89 #endif //GSAFE_DISABLE_DEBUG
92 QMultiMap<QString,HDConsoleCommandHolder *> user_commands;
93 QMultiMap<QString,QString> user_commands_descr;
97 if(!command.isEmpty() && interpreter != NULL)
99 user_commands.insert(command,interpreter);
100 user_commands_descr.insert(command,descr);
106 if(!command.isEmpty())
108 user_commands.remove(command);
109 user_commands_descr.remove(command);
115 user_commands.clear();
116 user_commands_descr.clear();
119 #ifndef GSAFE_DISABLE_DEBUG
126 class HDebugConsolePrivate
133 ~HDebugConsolePrivate()
138 QString databasename;
141 #ifndef DCONSOLE_NO_SQL
142 QPushButton *pushSql;
143 #endif // DCONSOLE_NO_SQL
144 QPushButton *pushText,*pushSyncwrite,*pushClear;
147 QMap<QString,void (HDebugConsolePrivate::*)(QString)> commands_exec;
148 QMap<QString,QString> commands_dscr;
151 void command_help(QString fcl);
152 void command_exit(QString fcl);
153 void command_close(QString fcl);
154 void command_clear(QString fcl);
155 void command_filters(QString fcl);
156 void command_state(QString fcl);
157 void command_enable(QString fcl);
158 void command_disable(QString fcl);
159 void command_synw(QString fcl);
160 void command_write(QString fcl);
161 void command_save(QString fcl);
162 void command_run(QString fcl);
164 #ifndef DCONSOLE_NO_SQL
165 void command_alldb(QString fcl);
166 void command_dbinfo(QString fcl);
167 void command_setdb(QString fcl);
168 void command_show(QString fcl);
169 #endif // DCONSOLE_NO_SQL
176 p =
new HDebugConsolePrivate(
this);
177 setWindowTitle(
"HDebugConsole");
178 p->databasename =
"";
182 setAttribute(Qt::WA_DeleteOnClose);
183 QVBoxLayout *qvbl =
new QVBoxLayout(
this);
184 QHBoxLayout *qhbl =
new QHBoxLayout(0);
187 #ifndef DCONSOLE_NO_SQL
188 p->pushSql =
new QPushButton(tr(
"Sql"),
this);
189 p->pushSql->setCheckable(
true);
190 p->pushSql->setChecked(
true);
191 qhbl->addWidget(p->pushSql);
192 #endif // DCONSOLE_NO_SQL
193 p->pushText =
new QPushButton(tr(
"Text"),
this);
194 p->pushText->setCheckable(
true);
195 p->pushText->setChecked(
true);
196 p->pushSyncwrite =
new QPushButton(tr(
"SyncWrite:\"syndebug.txt\""),
this);
197 p->pushSyncwrite->setCheckable(
true);
198 p->pushSyncwrite->setChecked(
false);
199 p->pushClear =
new QPushButton(tr(
"Clear"),
this);
200 qhbl->addWidget(p->pushText);
201 qhbl->addWidget(p->pushSyncwrite);
203 qhbl->addWidget(p->pushClear);
207 qvbl->addLayout(qhbl);
208 qvbl->addWidget(p->cf);
210 connect(p->pushClear,SIGNAL(clicked()),p->cf,SLOT(clearText()));
211 connect(p->cf,SIGNAL(commandEntered(QString)),
this,SLOT(execCommand(QString)));
212 connect(p->cf,SIGNAL(tabPressed(QString)),
this,SLOT(tabPressed(QString)));
213 p->cf->setTextTypeColor(1,QColor(255,150,150));
214 p->cf->setTextTypeColor(2,QColor(200,200,200));
216 p->cf->setColor(
"cursor",Qt::white);
217 p->cf->setColor(
"cmdtext",QColor(0,255,0));
218 p->cf->setTextTypeColor(DCONSOLE_TYPE_MESSAGE ,QColor(210,210,210));
219 p->cf->setTextTypeColor(DCONSOLE_TYPE_TEXT ,QColor(200,200,0));
220 p->cf->setTextTypeColor(DCONSOLE_TYPE_SQL ,QColor(255,0,0));
221 p->cf->setTextTypeColor(DCONSOLE_TYPE_RESULT ,QColor(100,100,255));
222 p->cf->setTextTypeColor(DCONSOLE_TYPE_CMD ,QColor(0,230,0));
223 p->cf->setTextTypeColor(DCONSOLE_TYPE_QTDEBUG ,QColor(255,127,30));
225 p->cf->addText(
"START",DCONSOLE_TYPE_MESSAGE);
228 p->commands_exec[
"help"] = &HDebugConsolePrivate::command_help;
229 p->commands_dscr[
"help"] =
" help - List the available commands";
231 p->commands_exec[
"exit"] = &HDebugConsolePrivate::command_exit;
232 p->commands_dscr[
"exit"] =
" exit - Exit main program (The debugged program too)";
234 p->commands_exec[
"close"] = &HDebugConsolePrivate::command_close;
235 p->commands_dscr[
"close"] =
" close - Close the debug window (only)";
237 p->commands_exec[
"clear"] = &HDebugConsolePrivate::command_clear;
238 p->commands_dscr[
"clear"] =
" clear - Clears the debug window\'s text";
240 p->commands_exec[
"filters"] = &HDebugConsolePrivate::command_filters;
241 p->commands_dscr[
"filters"] =
" filters - Show available debug filters";
243 p->commands_exec[
"state"] = &HDebugConsolePrivate::command_state;
244 p->commands_dscr[
"state"] =
" state <filter> - Show the state of the \"filter\" kind of output filter";
246 p->commands_exec[
"enable"] = &HDebugConsolePrivate::command_enable;
247 p->commands_dscr[
"enable"] =
" enable <filter> - Enable the \"filter\" kind of output";
249 p->commands_exec[
"disable"] = &HDebugConsolePrivate::command_disable;
250 p->commands_dscr[
"disable"] =
" disable <filter> - Disable the \"filter\" kind of output";
252 p->commands_exec[
"synw"] = &HDebugConsolePrivate::command_synw;
253 p->commands_dscr[
"synw"] =
" synw - Query the state or clear the content of syndebug.txt\n"
254 " synw off - Disable the writing of syndebug.txt\n"
255 " synw on - Enable the writing of syndebug.txt\n"
256 " synw clear - Clear the content of syndebug.txt";
258 p->commands_exec[
"write"] = &HDebugConsolePrivate::command_write;
259 p->commands_dscr[
"write"] =
" write <text> - Write \"text\" to the console";
261 p->commands_exec[
"save"] = &HDebugConsolePrivate::command_save;
262 p->commands_dscr[
"save"] =
" save - Save the content of debug window to debug.txt";
264 p->commands_exec[
"run"] = &HDebugConsolePrivate::command_run;
265 p->commands_dscr[
"run"] =
" run <custom> - Run the \"custom\" program command";
267 #ifndef DCONSOLE_NO_SQL
268 p->commands_exec[
"alldb"] = &HDebugConsolePrivate::command_alldb;
269 p->commands_dscr[
"alldb"] =
" alldb - Show all available database connections";
271 p->commands_exec[
"dbinfo"] = &HDebugConsolePrivate::command_dbinfo;
272 p->commands_dscr[
"dbinfo"] =
" dbinfo - Show the current connected database information";
274 p->commands_exec[
"setdb"] = &HDebugConsolePrivate::command_setdb;
275 p->commands_dscr[
"setdb"] =
" setdb - Sets the current database to default (not the program but console)\n"
276 " setdb <dbname> - Sets the current database to \"dbname\"";
278 p->commands_exec[
"show"] = &HDebugConsolePrivate::command_show;
279 p->commands_dscr[
"show"] =
" show - Show all table in the current database\n"
280 " show <tablename> - Show the fields of table named \"tablename\"";
282 #endif // DCONSOLE_NO_SQL
286 pushSyncwrite->setChecked(
true);
289 #ifndef COMPILED_WITH_QT4X
290 qInstallMessageHandler(dconsoleMessageHandler);
292 qInstallMsgHandler(dconsoleMessageHandler);
298 #ifndef COMPILED_WITH_QT4X
299 qInstallMessageHandler(0);
301 qInstallMsgHandler(0);
313 p->pushText->setDisabled(
false);
314 p->pushSyncwrite->setDisabled(
false);
315 #ifndef DCONSOLE_NO_SQL
316 p->pushSql->setDisabled(
false);
317 #endif // DCONSOLE_NO_SQL
321 p->pushText->setDisabled(
true);
322 p->pushSyncwrite->setDisabled(
true);
323 #ifndef DCONSOLE_NO_SQL
324 p->pushSql->setDisabled(
true);
325 #endif // DCONSOLE_NO_SQL
327 p->disabled = !enabled;
337 QMessageBox::warning(NULL,title,str);
343 if(p->pushSyncwrite->isChecked())
347 dbgf = fopen(
"syndebug.txt",
"a");
348 fseek(dbgf,0,SEEK_END);
349 fprintf(dbgf,
"\n%s\n",s.toLocal8Bit().constData());
353 #ifndef DCONSOLE_NO_SQL
354 if(p->pushSql->isChecked() && type == DCONSOLE_TYPE_SQL)
355 p->cf->addText(s,DCONSOLE_TYPE_SQL);
357 #endif // DCONSOLE_NO_SQL
359 if(p->pushText->isChecked() && type == DCONSOLE_TYPE_TEXT)
360 p->cf->addText(s,DCONSOLE_TYPE_TEXT);
362 if(type == DCONSOLE_TYPE_QTDEBUG)
363 p->cf->addText(s,DCONSOLE_TYPE_QTDEBUG);
365 QApplication::processEvents();
368 void HDebugConsole::closeEvent(QCloseEvent *e)
371 QWidget::closeEvent(e);
374 #ifndef DCONSOLE_NO_SQL
380 #endif // DCONSOLE_NO_SQL
388 int HDebugConsole::execCommand(QString query)
393 query = query.simplified();
396 p->cf->addText(
".",DCONSOLE_TYPE_MESSAGE);
400 QStringList qparts = query.split(
" ",QString::SkipEmptyParts);
401 if(qparts.count() > 0)
403 if(p->commands_exec.find(qparts[0]) != p->commands_exec.end())
405 void (HDebugConsolePrivate::*cmdFunc)(QString);
407 p->cf->addText(p->cf->promptString() + query , DCONSOLE_TYPE_CMD);
408 cmdFunc = p->commands_exec[qparts[0]];
409 (*p.*cmdFunc)(query.mid(qparts[0].length(),-1).simplified());
414 #ifndef DCONSOLE_NO_SQL
419 p->cf->addText(p->cf->promptString() + query , DCONSOLE_TYPE_CMD);
420 p->cf->addText(
"Exec Console sumbitted query...",DCONSOLE_TYPE_MESSAGE);
421 p->cf->addText(
"\""+query+
"\"",DCONSOLE_TYPE_SQL);
424 if(p->databasename.isEmpty())
425 db = QSqlDatabase::database();
427 db = QSqlDatabase::database(p->databasename);
434 if(q.lastError().type() == QSqlError::NoError)
436 p->cf->addText(
"Succesfull executed. Dumping data:",DCONSOLE_TYPE_MESSAGE);
440 if(!q.record().isEmpty())
442 cn = q.record().count();
450 result.append(
" | ");
451 result.append(v.toString());
456 p->cf->addText(result,DCONSOLE_TYPE_RESULT);
457 p->cf->addText(QString(
"(%1 rows affected/%2 size)")
458 .arg(q.numRowsAffected())
460 ,DCONSOLE_TYPE_MESSAGE);
461 p->cf->addText(
"End query: \""+query+
"\"",DCONSOLE_TYPE_MESSAGE);
466 p->cf->addText(QString(
"\nError: %1").arg(q.lastError().text()),DCONSOLE_TYPE_MESSAGE);
470 p->cf->addText(QString(
"Unknown command: %1").arg(query),DCONSOLE_TYPE_MESSAGE);
471 #endif // DCONSOLE_NO_SQL
475 int HDebugConsole::tabPressed(QString query)
477 if(query.isEmpty() || p->disabled)
482 if(query.startsWith(
"run "))
484 if(user_commands.size() > 0)
488 QMultiMap<QString,HDConsoleCommandHolder *>::const_iterator i = user_commands.constBegin();
489 while(i != user_commands.constEnd())
491 if( QString(
"run %1").arg(i.key()).startsWith(query) )
501 p->cf->setCommandLineText(QString(
"run %1").arg(cmd));
507 p->cf->addText(
"",DCONSOLE_TYPE_MESSAGE);
508 for(i = user_commands.constBegin();i != user_commands.constEnd();++i)
509 if(QString(
"run %1").arg(i.key()).startsWith(query))
510 p->cf->addText((QString(
"run %1 - %2")
512 .arg(user_commands_descr.value(i.key())))
513 ,DCONSOLE_TYPE_MESSAGE);
521 QStringList cmds = p->commands_dscr.keys();
522 QList<QString>::iterator i;
523 for(i = cmds.begin();i != cmds.end();++i)
524 if(i->startsWith(query))
532 p->cf->setCommandLineText(cmd ==
"run" ? QString(
"run ") : cmd);
538 p->cf->addText(
"",DCONSOLE_TYPE_MESSAGE);
539 for(i = cmds.begin();i != cmds.end();++i)
540 if(i->startsWith(query))
541 p->cf->addText((QString(
"%1").arg(p->commands_dscr[*i])),DCONSOLE_TYPE_MESSAGE);
546 #ifndef COMPILED_WITH_QT4X
547 void dconsoleMessageHandler(QtMsgType type,
const QMessageLogContext &context,
const QString &msg)
552 contmsg = QString(
"(Category:%1, File:%2, Function:%3, Line:%4, Ver:%5)")
553 .arg(context.category)
555 .arg(context.function)
557 .arg(context.version);
562 mm = QString(
"Qt-Debug: %1\n%2").arg(msg).arg(contmsg);
565 mm = QString(
"Qt-Warning: %1\n%2").arg(msg).arg(contmsg);
568 mm = QString(
"Qt-Critical: %1\n%2").arg(msg).arg(contmsg);
571 mm = QString(
"Qt-Fatal: %1\n%2").arg(msg).arg(contmsg);
575 if(HDebugConsole::myself == NULL)
577 fprintf(stderr,
"%s",mm.toLocal8Bit().constData());
581 HDebugConsole::myself->
add_text(mm,DCONSOLE_TYPE_QTDEBUG);
585 void dconsoleMessageHandler(QtMsgType type,
const char *msg)
591 mm = QString(
"Qt-Debug: %1").arg(msg);
594 mm = QString(
"Qt-Warning: %1").arg(msg);
597 mm = QString(
"Qt-Critical: %1").arg(msg);
600 mm = QString(
"Qt-Fatal: %1").arg(msg);
604 if(HDebugConsole::myself == NULL)
606 fprintf(stderr,
"%s",mm.toLocal8Bit().constData());
610 HDebugConsole::myself->
add_text(mm,DCONSOLE_TYPE_QTDEBUG);
613 #endif //COMPILED_WITH_QT4X
618 #define MOUT(a) cf->addText(a,DCONSOLE_TYPE_MESSAGE)
620 void HDebugConsolePrivate::command_help(QString fcl)
624 MOUT(
"This function doesn\'t accept parameters");
627 MOUT(
"HDebugConsole, commands:");
628 QStringList keys = commands_dscr.keys();
630 QList<QString>::iterator i;
631 for(i=keys.begin();i != keys.end();++i)
632 MOUT(QString(
"%1").arg(commands_dscr.value(*i)));
634 #ifndef DCONSOLE_NO_SQL
635 MOUT(
" \"SQL\" - Execute the SQL command");
636 #endif // DCONSOLE_NO_SQL
637 if(user_commands.size() > 0)
639 MOUT(
" -- CUSTOM/PROGRAM COMMANDS -- ");
640 QMultiMap<QString,HDConsoleCommandHolder *>::const_iterator i = user_commands.constBegin();
641 while(i != user_commands.constEnd())
643 MOUT(QString(
" run %1%2%3")
645 .arg( user_commands_descr.value(i.key()) ==
"" ?
"" :
" - ")
646 .arg(user_commands_descr.value(i.key())));
653 void HDebugConsolePrivate::command_exit(QString fcl)
657 MOUT(
"This function doesn\'t accept parameters");
660 QApplication::exit(0);
663 void HDebugConsolePrivate::command_close(QString fcl)
667 MOUT(
"This function doesn\'t accept parameters");
673 void HDebugConsolePrivate::command_clear(QString fcl)
677 MOUT(
"This function doesn\'t accept parameters");
683 void HDebugConsolePrivate::command_filters(QString fcl)
687 MOUT(
"This function doesn\'t accept parameters");
690 #ifndef DCONSOLE_NO_SQL
691 MOUT(
".\nAvailable filters: sql text\n");
693 MOUT(
".\nAvailable filters: text\n");
694 #endif // DCONSOLE_NO_SQL
697 void HDebugConsolePrivate::command_state(QString fcl)
699 #ifndef DCONSOLE_NO_SQL
702 MOUT(QString(
"SQL output is %1").arg(pushSql->isChecked() ?
"enabled" :
"disabled"));
705 #endif // DCONSOLE_NO_SQL
708 MOUT(QString(
"TEXT output is %1.").arg(pushText->isChecked() ?
"enabled" :
"disabled"));
711 MOUT(
"Unknown or missing filter name. Exec \"filters\" command to see available filters!");
714 void HDebugConsolePrivate::command_enable(QString fcl)
716 #ifndef DCONSOLE_NO_SQL
719 pushSql->setChecked(
true);
720 MOUT(
"SQL output is enabled");
723 #endif // DCONSOLE_NO_SQL
727 pushText->setChecked(
true);
728 MOUT(
"TEXT output is enabled");
731 MOUT(
"Unknown or missing filter name. Exec \"filters\" command to see available filters!");
734 void HDebugConsolePrivate::command_disable(QString fcl)
736 #ifndef DCONSOLE_NO_SQL
739 pushSql->setChecked(
false);
740 MOUT(
"SQL output is disabled");
743 #endif // DCONSOLE_NO_SQL
746 pushText->setChecked(
false);
747 MOUT(
"TEXT output is disabled");
750 MOUT(
"Unknown or missing filter name. Exec \"filters\" command to see available filters!");
753 void HDebugConsolePrivate::command_synw(QString fcl)
759 MOUT(QString(
"Syncronized backup file writing: %1")
760 .arg(pushSyncwrite->isChecked() ?
"on" :
"off"));
765 pushSyncwrite->setChecked(
true);
766 MOUT(QString(
"Enabled syncronized backup file writing (syndebug.txt)"));
771 pushSyncwrite->setChecked(
false);
772 MOUT(QString(
"Disabled syncronized backup file writing"));
778 dbgf = fopen(
"syndebug.txt",
"w");
779 fseek(dbgf,0,SEEK_SET);
782 MOUT(QString(
"The content of syndebug.txt has been cleared"));
785 MOUT(
"Wrong parameter! Accepted parameters: <empty>,on,off,clear");
788 void HDebugConsolePrivate::command_write(QString fcl)
793 void HDebugConsolePrivate::command_save(QString fcl)
797 MOUT(
"This function doesn\'t accept parameters");
801 dbgf = fopen(
"debug.txt",
"w");
802 fseek(dbgf,0,SEEK_SET);
804 fprintf(dbgf,
"\n%s\n",cf->selectedText().toLocal8Bit().constData());
805 cf->clearSelection();
807 MOUT(
"Saving console text to debug.txt is done.\n");
810 void HDebugConsolePrivate::command_run(QString fcl)
812 QMultiMap<QString,HDConsoleCommandHolder *>::iterator i;
814 i = user_commands.find(fcl);
815 if(i == user_commands.end())
817 MOUT(
" Error: Command not found!");
821 MOUT(QString(
"Starting command \"%1\"...").arg(fcl));
829 #ifndef DCONSOLE_NO_SQL
830 void HDebugConsolePrivate::command_alldb(QString fcl)
834 MOUT(
"This function doesn\'t accept parameters");
837 QStringList l = QSqlDatabase::connectionNames();
838 QStringList::iterator i=l.begin();
839 MOUT(QString(
"Available databases (%1) :").arg(l.count()));
847 void HDebugConsolePrivate::command_dbinfo(QString fcl)
851 MOUT(
"This function doesn\'t accept parameters");
855 if(databasename.isEmpty())
856 db = QSqlDatabase::database();
858 db = QSqlDatabase::database(databasename);
861 MOUT(QString(
"Current OPENED database connection is:\nConnection name=%1\nDriver=%2\nName=%3\nHost=%4\nUser=%5\n")
862 .arg(db.connectionName())
863 .arg(db.driverName())
864 .arg(db.databaseName())
866 .arg(db.userName()));
870 MOUT(QString(
"There is no opened database!"));
874 void HDebugConsolePrivate::command_setdb(QString fcl)
876 QStringList l = QSqlDatabase::connectionNames();
879 if(l.indexOf(fcl) == -1)
881 MOUT(
"Unknown database name. Exec \"alldb\" command to see available databases!");
885 MOUT(QString(
"Setting database to default (in console) \"%1\"...").arg(fcl));
889 void HDebugConsolePrivate::command_show(QString fcl)
892 if(databasename.isEmpty())
893 db = QSqlDatabase::database();
895 db = QSqlDatabase::database(databasename);
899 MOUT(
"There is no opened database!");
905 MOUT(QString(
"Tables in the %1 database:")
906 .arg(databasename.isEmpty() ? QString(
"default") : QString(
"\"%1\"").arg(databasename)));
907 cf->addText(db.tables().join(
"\n"),DCONSOLE_TYPE_RESULT);
912 QSqlRecord r = db.record(fcl);
914 MOUT(QString(
"There is no %1 table in %2 database")
916 .arg(databasename.isEmpty() ? QString(
"default") : QString(
"\"%1\"").arg(databasename)));
918 MOUT(QString(
"Fields of table: %1").arg(fcl));
919 for(i=0;i<r.count();++i)
921 cf->addText(QString(
"%1\t\t%2\t\t(default:%3)")
922 .arg(r.field(i).name())
923 .arg(QVariant::typeToName(r.field(i).type()))
924 .arg(r.field(i).defaultValue().toString())
925 ,DCONSOLE_TYPE_RESULT);
931 #endif // DCONSOLE_NO_SQL
935 int HDebugConsole::checkIfIClose(
void)
938 QList<QWidget *>::const_iterator i = QApplication::topLevelWidgets().begin();
939 while(i != QApplication::topLevelWidgets().end())
941 if (*i !=
this && (*i)->isVisible())
960 friend class HConsolePanelPrivate;
965 HConsoleLine(QString& l,HConsoleLine *current = NULL);
978 class HConsolePanelPrivate
983 HConsolePanelPrivate(
HConsolePanel *ppointer) { pp = ppointer; }
986 void fitConsole(
void);
987 void calcCmdLnTop(
void);
988 void calcScrollBar();
990 int calcStringWidth(QString s);
991 inline int calcStringBreakPos(QString s);
992 void stringReplaceTabToSpace(QString &t);
994 HConsoleLine* lineObjectByDisplayPos(
int inLine,
char& type);
995 void getLCfromXY(
int x,
int y,
int& l,
int& c,
int& scroll,
char& t);
997 void addTextPart(QString& t,
bool hardend,
char type);
998 void addLine(QString& t,
bool hardend,
char type);
1000 void addCommandLineTextPart(QString t,
bool hardend);
1001 void addCommandLineLine(QString t,
bool hardend);
1002 void setCommandLineLineBySerial(
int serial,QString newtext);
1003 QString commandLineLineBySerial(
int serial);
1004 HConsoleLine* commandLineObjectBySerial(
int serial);
1005 QString cmdLineTextSkipsel(
int& new_cursor_pos);
1007 void paintRows(QPainter *p);
1008 void paintBar(QPainter *p);
1010 void hoverHandler(
int x,
int y);
1015 HConsoleLine *first,*top,*viewtop,*last;
1016 HConsoleLine *cfirst,*ctop,*clast;
1018 QColor bgColor,selectionColor,fontColor,cmdLineColor,cursorColor,marginColor,marginBgColor;
1019 QMap<char,QColor> typeColors;
1020 QList<QString> history;
1021 QList<QString>::iterator history_it;
1027 int marginXl,marginXlfix,marginXr;
1033 int lineBreakPosition;
1036 int selectionHeight;
1044 char mousePressedArea;
1045 bool holdMouseButton;
1046 int mouseOldX,mouseOldY,mouseOldCursor;
1051 int sbar_begin,sbar_obegin;
1054 int selectionRange[6];
1056 int cselectionRange[6];
1059 HConsoleLine::HConsoleLine()
1069 HConsoleLine::HConsoleLine(QString& l,HConsoleLine *current)
1079 serial = prev->serial + 1;
1084 HConsoleLine::~HConsoleLine()
1091 setFocusPolicy(Qt::StrongFocus);
1096 f.setFamily(
"Monospace");
1097 f.setStyleHint(QFont::TypeWriter);
1102 setMinimumSize(200,150);
1103 setCursor(Qt::IBeamCursor);
1105 p =
new HConsolePanelPrivate(
this);
1107 p->fm =
new QFontMetrics(font(),
this);
1110 p->bgColor = Qt::black;
1111 p->selectionColor = Qt::blue;
1112 p->fontColor = Qt::yellow;
1113 p->cmdLineColor = Qt::green;
1114 p->marginColor = QColor(240,240,240);
1115 p->marginBgColor = Qt::black;
1116 p->cursorColor = Qt::yellow;
1118 p->last = p->top = p->first = NULL;
1120 p->cfirst =
new HConsoleLine(s);
1121 p->ctop = p->clast = p->cfirst;
1122 p->cursorPos[0] = p->cfirst->serial;
1123 p->cursorPos[1] = 0;
1124 p->promptStr =
"Console>";
1126 p->marginXl = p->marginXlfix = 5;
1129 if(QFontInfo(font()).fixedPitch())
1132 p->oldWindowWidth = 0;
1133 p->sbar_minlength = 10;
1137 p->history_it = p->history.end();
1138 p->mousePressedArea = 0;
1141 p->holdMouseButton =
false;
1142 p->mouseOldCursor = 0;
1143 setMouseTracking(
true);
1146 HConsolePanel::~HConsolePanel(
void)
1148 HConsoleLine *d,*r = p->first;
1168 int HConsolePanelPrivate::calcStringWidth(QString s)
1171 return s.length() * letterWidth;
1172 return fm->width(s);
1175 int HConsolePanelPrivate::calcStringBreakPos(QString s)
1178 return lineBreakPosition;
1179 int ll = s.length();
1180 while(fm->width(s.left(ll)) > maxLineLength)
1187 p->marginStr = margin;
1191 void HConsolePanelPrivate::fitConsole(
void)
1194 int cursorLines = 0;
1196 int displayLines = 0;
1198 cursortxt = pp->commandLineText();
1203 maxCharWidth = fm->maxWidth();
1204 lineHeight = fm->height();
1205 letterWidth = fm->averageCharWidth();
1206 lhascdiffhalf = (int) floor((lineHeight - fm->ascent()) / 2);
1207 selectionHeight = fm->ascent() + lhascdiffhalf;
1208 lineCapacity = (int) ((pp->height()-(2+1+fm->descent())) / lineHeight);
1209 marginXl = marginXlfix + calcStringWidth(marginStr);
1210 maxLineLength = pp->width() - (4 + marginXr + marginXl);
1211 lineBreakPosition = (int)floor( maxLineLength / letterWidth );
1212 mousePressedArea = 0;
1213 sbar_maxlength = pp->height() - 12;
1216 if(oldWindowWidth != pp->width())
1220 QString textline =
"";
1221 HConsoleLine *rbegin,*rend,*r=first;
1223 oldWindowWidth = pp->width();
1226 bool merged_basline,splitted;
1228 textwidth = r->width;
1232 merged_basline =
false;
1233 while(r->autole && r->next != NULL)
1236 textline += r->line;
1237 textwidth += r->width;
1238 merged_basline =
true;
1243 while(!textline.isEmpty() && textwidth > maxLineLength)
1245 int ll = calcStringBreakPos(textline);
1247 str = textline.left(ll);
1248 HConsoleLine *rnew =
new HConsoleLine(str);
1249 rnew->width = calcStringWidth(rnew->line);
1250 rnew->type = rbegin->type;
1251 rnew->autole =
true;
1252 rnew->serial = newSerial++;
1254 rnew->prev = rbegin->prev;
1255 rnew->next = rbegin;
1256 if(rbegin->prev != NULL)
1257 rbegin->prev->next = rnew;
1260 rbegin->prev = rnew;
1262 textline = textline.mid(ll,-1);
1263 textwidth = calcStringWidth(textline);
1267 if(splitted || merged_basline)
1269 rbegin->line = textline;
1270 rbegin->width = textwidth;
1271 rbegin->autole =
false;
1272 rbegin->serial = newSerial++;
1277 rbegin->next = r->next;
1279 r->next->prev = rbegin;
1283 while(rend != NULL && rend != rbegin)
1285 HConsoleLine *delme;
1295 r->serial = newSerial++;
1301 pp->setCommandLineText(cursortxt,
true);
1302 cursorLines = clast->serial + 1;
1306 while(top->prev != NULL && displayLines < (lineCapacity-(cursorLines+1)))
1318 void HConsolePanelPrivate::calcScrollBar()
1320 if(last == NULL || last->serial + 1 < lineCapacity)
1323 sbar_length = sbar_maxlength;
1327 sbar_length = int((
double(lineCapacity) /
double(last->serial + 1)) *
double(sbar_maxlength));
1328 if(sbar_length < sbar_minlength)
1329 sbar_length = sbar_minlength;
1330 sbar_begin = int((
double((viewtop != NULL ? viewtop->serial : top->serial)) /
double(top->serial)) *
double(sbar_maxlength-sbar_length));
1334 void HConsolePanelPrivate::calcCmdLnTop(
void)
1336 HConsoleLine *cr = clast;
1338 int displayLines = 0;
1340 displayLines = last->serial - top->serial + 1;
1341 while(cr->prev != NULL)
1343 if(displayLines + ll++ >= lineCapacity && cursorPos[0] >= cr->serial)
1352 p->clecho = !disable;
1355 void HConsolePanel::paintEvent(QPaintEvent *e)
1358 QPainter *painter =
new QPainter(
this);
1359 p->paintRows(painter);
1360 p->paintBar(painter);
1365 void HConsolePanelPrivate::paintRows(QPainter *p)
1373 p->fillRect(0,0,pp->width(),pp->height(),bgColor);
1379 for(cmdline = 0;cmdline < 2;++cmdline)
1383 r = viewtop == NULL ? top : viewtop;
1384 mSelSign = selection;
1385 mSelRange = selectionRange;
1390 mSelSign = cselection;
1391 mSelRange = cselectionRange;
1395 p->setPen(cmdLineColor);
1396 p->drawText(x,y,promptStr);
1400 if(cmdline || viewtop != NULL || lineCapacity > clast->serial + 1)
1403 if(mSelSign && mSelRange[0] == r->serial && mSelRange[2] == r->serial)
1410 if(ee > r->line.length())
1411 ee = r->line.length();
1413 p->fillRect(x+calcStringWidth((cmdline && r == cfirst ? promptStr : QString()) + r->line.left(ss)),
1415 calcStringWidth(r->line.left(ee).mid(ss,-1)),
1416 selectionHeight+lhascdiffhalf,
1420 else if(mSelSign && mSelRange[0] == r->serial)
1422 int ss = mSelRange[1];
1426 p->fillRect(x+calcStringWidth((cmdline && r == cfirst ? promptStr : QString()) + r->line.left(ss)),
1428 calcStringWidth(r->line) - calcStringWidth((r->line).left(ss)),
1429 selectionHeight+lhascdiffhalf,selectionColor);
1431 else if(mSelSign && mSelRange[0] < r->serial && mSelRange[2] > r->serial)
1433 p->fillRect(x,y-selectionHeight,
1434 calcStringWidth(r->line),selectionHeight+lhascdiffhalf,selectionColor);
1436 else if(mSelSign && mSelRange[2] == r->serial)
1438 int ee = mSelRange[3];
1439 if(ee > r->line.length())
1440 ee = r->line.length();
1442 p->fillRect(x,y-selectionHeight,
1443 calcStringWidth(r->line.left(ee)),selectionHeight+lhascdiffhalf,selectionColor);
1446 p->setPen(marginColor);
1449 if(!marginStr.isEmpty())
1451 QString s = marginStr;
1452 s.replace(QRegExp(
"%[0]*s"),QString(
"%1").arg(r->serial+1));
1453 p->fillRect(0,y-selectionHeight,marginXl-marginXlfix,lineHeight+lhascdiffhalf,marginBgColor);
1457 p->setPen(fontColor);
1459 p->setPen(typeColors.find(r->type) == typeColors.end() ? fontColor : typeColors[r->type] );
1460 p->drawText(x,y,r->line);
1464 if(cursorPos[0] == r->serial && pp->hasFocus())
1467 p->setPen(cursorColor);
1468 xpos = x+calcStringWidth(r->line.left(cursorPos[1]))+calcStringWidth(r == cfirst ? promptStr : QString(
""));
1469 p->drawLine(xpos,y-selectionHeight,xpos,y+lhascdiffhalf);
1470 p->drawLine(xpos+1,y-selectionHeight,xpos+1,y+lhascdiffhalf);
1472 p->setPen(cmdLineColor);
1473 p->drawText(x,y,(r == cfirst ? promptStr : QString(
"")) + r->line);
1479 if(++l >= lineCapacity)
1485 void HConsolePanelPrivate::paintBar(QPainter *p)
1487 p->setPen(QColor(150,150,150));
1488 p->setBrush(QBrush(QColor(50,50,50),Qt::SolidPattern));
1489 p->drawRoundedRect(marginXl+maxLineLength+2,4,marginXr,pp->height()-8,5,5);
1490 p->setBrush(QBrush(QColor(150,150,150),Qt::SolidPattern));
1491 p->drawRoundedRect(marginXl+maxLineLength+4,6+sbar_begin,marginXr-4,sbar_length,3,3);
1492 p->setBrush(Qt::NoBrush);
1497 if(section ==
"background")
1499 if(section ==
"selection")
1500 p->selectionColor = color;
1501 if(section ==
"standardtext")
1502 p->fontColor = color;
1503 if(section ==
"cmdtext")
1504 p->cmdLineColor = color;
1505 if(section ==
"margin")
1506 p->marginColor = color;
1507 if(section ==
"cursor")
1508 p->cursorColor = color;
1509 if(section ==
"marginbg")
1510 p->marginBgColor = color;
1515 p->typeColors[type] = color;
1531 if(t.contains(
"\n"))
1533 QStringList lines = t.split(
"\n");
1534 QList<QString>::iterator i=lines.begin();
1535 for(;i!=lines.end();++i)
1536 p->addTextPart(*i,
true,type);
1539 p->addTextPart(t,
true,type);
1544 void HConsolePanelPrivate::stringReplaceTabToSpace(QString &t)
1547 while((tp = t.indexOf(
"\t")) != -1)
1549 fl = int( ceil(
double(tp)/
double(tabstop)) * tabstop) - tp;
1552 addedSpaces += fl - 1;
1553 t.replace(tp,1,QString().fill(
' ',fl));
1557 void HConsolePanelPrivate::addTextPart(QString& t,
bool hardend,
char type)
1559 stringReplaceTabToSpace(t);
1560 if(maxLineLength < calcStringWidth(t))
1562 QString fitted,leaved;
1563 int s = calcStringBreakPos(t);
1565 leaved = t.mid(s,-1);
1566 addLine(fitted,
false,type);
1567 addTextPart(leaved,hardend,type);
1570 addLine(t,hardend,type);
1573 void HConsolePanelPrivate::addLine(QString& t,
bool hardend,
char type)
1576 last =
new HConsoleLine(t,last);
1579 last->width = calcStringWidth(t);
1582 last->autole =
false;
1584 if(last->serial - top->serial + 1 >= lineCapacity)
1590 HConsoleLine *d,*r = p->first;
1597 p->top = p->first = p->last = NULL;
1602 void HConsolePanel::resizeEvent(QResizeEvent *e)
1605 QFrame::resizeEvent(e);
1610 for(;lineCount > 0;--lineCount)
1612 if(p->viewtop == NULL)
1615 p->viewtop = p->top->prev;
1619 if(p->viewtop->prev != NULL)
1620 p->viewtop = p->viewtop->prev;
1621 if(p->viewtop == p->top)
1631 for(;lineCount > 0;--lineCount)
1633 if(p->viewtop != NULL)
1635 if(p->viewtop->next == p->top)
1638 p->viewtop = p->viewtop->next;
1639 if(p->viewtop == p->top)
1649 p->viewtop = p->first;
1664 HConsoleLine *r = p->first;
1665 while(r != NULL && r->serial < p->top->serial)
1667 if(r->serial == serial)
1682 return p->last->serial;
1689 return p->viewtop == NULL ? p->top->serial : p->viewtop->serial;
1694 HConsoleLine* r = p->first;
1696 r = p->viewtop == NULL ? p->top : p->viewtop;
1701 if(r->serial == serial)
1703 if(withWraps && r->autole)
1705 QString rline = r->line;
1706 while(r->autole && r->next != NULL )
1708 rline += r->next->line;
1722 if(p->first == NULL)
1724 p->selectionRange[0] = p->first->serial;
1725 p->selectionRange[1] = 0;
1726 p->selectionRange[2] = p->last->serial;
1727 p->selectionRange[3] = p->last->line.length();
1728 p->selection =
true;
1729 p->cselection =
false;
1735 p->selection =
false;
1736 p->cselection =
false;
1741 if(!p->selection && !p->cselection)
1744 int *mSelRange=NULL;
1746 HConsoleLine* r=NULL;
1750 mSelRange = p->cselectionRange;
1755 mSelRange = p->selectionRange;
1758 if(mSelRange == NULL)
1762 if(mSelRange[0] == r->serial && mSelRange[2] == r->serial)
1769 if(ee > r->line.length())
1770 ee = r->line.length();
1772 return r->line.left(ee).mid(ss,-1);
1774 else if(mSelRange[0] == r->serial)
1776 int ss = mSelRange[1];
1779 sel += r->line.mid(ss,-1) + (r->autole ?
"" :
"\n");
1782 else if(mSelRange[0] < r->serial && mSelRange[2] > r->serial)
1784 sel += r->line + (r->autole ?
"" :
"\n");
1786 else if(mSelRange[2] == r->serial)
1788 int ee = mSelRange[3];
1789 if(ee > r->line.length())
1790 ee = r->line.length();
1792 sel += r->line.left(ee);
1802 if(!p->selection && !p->cselection)
1804 QClipboard * cb = QApplication::clipboard();
1808 HConsoleLine* HConsolePanelPrivate::lineObjectByDisplayPos(
int inLine,
char& type)
1810 HConsoleLine* r = viewtop == NULL ? top : viewtop;
1814 if(viewtop != NULL || lineCapacity > clast->serial + 1)
1835 void HConsolePanelPrivate::getLCfromXY(
int x,
int y,
int& l,
int& c,
int& scroll,
char& t)
1837 int displayLines = 0;
1839 HConsoleLine *lineObj;
1842 displayLines = last->serial - ( viewtop != NULL ? viewtop->serial : top->serial ) + 1;
1843 if(displayLines > lineCapacity)
1844 displayLines = lineCapacity;
1849 if(t == 0 && x > marginXl + maxLineLength )
1863 dl = (int) floor((y-2)/lineHeight);
1864 if(t == 1 && dl>displayLines-1)
1866 dl = displayLines-1;
1867 if(viewtop != NULL && viewtop->serial < top->serial)
1870 if((t == 0 || t == 2) && dl > displayLines+clast->serial)
1872 dl = displayLines+clast->serial;
1876 lineObj = lineObjectByDisplayPos(dl,t);
1879 l = 0; c = 0; t = 0;
1882 l = lineObj->serial;
1883 if(lineObj->line.isEmpty())
1889 if(lineObj == cfirst)
1891 sl = lineObj->line.length();
1892 for( c=1 ; calcStringWidth(prefix + lineObj->line.left(c)) - calcStringWidth(lineObj->line.at(c-1))/2 < x - marginXl ; ++c )
1902 void HConsolePanel::mousePressEvent(QMouseEvent *e)
1904 if(e->button() != Qt::LeftButton)
1910 p->getLCfromXY(e->x(),e->y(),l,c,scroll,type);
1911 p->mousePressedArea = type;
1912 p->holdMouseButton =
true;
1915 p->mouseOldX = e->x();
1916 p->mouseOldY = e->y();
1917 p->sbar_obegin = p->sbar_begin;
1920 if(type == 2 && scroll == 0)
1922 p->cursorPos[0] = l;
1923 p->cursorPos[1] = c;
1924 p->origCursorPos2 = p->cursorPos[1];
1928 p->selectionRange[4] = p->selectionRange[0] = l;
1929 p->selectionRange[5] = p->selectionRange[1] = c;
1933 p->cselectionRange[4] = p->cselectionRange[0] = l;
1934 p->cselectionRange[5] = p->cselectionRange[1] = c;
1936 p->selection =
false;
1937 p->cselection =
false;
1941 void HConsolePanel::mouseReleaseEvent(QMouseEvent *e)
1943 p->holdMouseButton =
false;
1944 p->mousePressedArea = 0;
1946 if(e->button() == Qt::RightButton)
1948 QMenu *m=
new QMenu(
this);
1949 m->addAction(tr(
"Scroll to top"),
this,SLOT(
scrollTop()));
1950 m->addAction(tr(
"Scroll to bottom"),
this,SLOT(
scrollReset()));
1952 m->addAction(tr(
"Select all"),
this,SLOT(
selectAll()));
1958 m->addAction(tr(
"Clear all text"),
this,SLOT(
clearText()));
1960 m->exec(mapToGlobal(e->pos()));
1965 void HConsolePanelPrivate::hoverHandler(
int x,
int y)
1967 if(x < 0 && x > pp->width())
1972 if(x > 0 && x < marginXl+maxLineLength && mouseOldCursor != 1)
1974 pp->setCursor(Qt::IBeamCursor);
1978 if(x > marginXl+maxLineLength && x < pp->width() && mouseOldCursor != 2)
1980 pp->setCursor(Qt::PointingHandCursor);
1986 void HConsolePanel::mouseMoveEvent(QMouseEvent *e)
1988 if(!p->holdMouseButton)
1990 p->hoverHandler(e->x(),e->y());
1996 if(p->mousePressedArea == 0)
1998 if(p->mouseOldX > p->marginXl + p->maxLineLength + 2 &&
1999 p->mouseOldX < p->marginXl + p->maxLineLength + 2 + p->marginXr &&
2001 p->mouseOldY < height() - 2)
2003 int nb = p->sbar_obegin + (e->y() - p->mouseOldY);
2006 if(nb > p->sbar_maxlength)
2007 nb = p->sbar_maxlength;
2008 scrollToSerial(
int((
double(nb)/
double(p->sbar_maxlength-p->sbar_length))*
double(p->top->serial)));
2013 type = p->mousePressedArea;
2014 p->getLCfromXY(e->x(),e->y(),l,c,s,type);
2018 p->getLCfromXY(e->x(),e->y(),l,c,s,type);
2023 p->getLCfromXY(e->x(),e->y(),l,c,s,type);
2029 int *mSelRange = NULL;
2034 mSelRange = p->selectionRange;
2038 sel = p->cselection;
2039 mSelRange = p->cselectionRange;
2042 if(mSelRange == NULL)
2044 if(!sel || mSelRange[2] != l || mSelRange[3] != c)
2046 if(mSelRange[4] < l || (mSelRange[4] == l && mSelRange[5] < c))
2050 mSelRange[0] = mSelRange[4];
2051 mSelRange[1] = mSelRange[5];
2057 mSelRange[2] = mSelRange[4];
2058 mSelRange[3] = mSelRange[5];
2061 p->selection = type == 1 ?
true :
false;
2062 p->cselection = type == 2 ?
true :
false;
2067 void HConsolePanel::mouseDoubleClickEvent(QMouseEvent *e)
2069 if(e->button() != Qt::LeftButton)
2073 int *mSelRange = NULL;
2076 p->getLCfromXY(e->x(),e->y(),l,c,s,type);
2077 if(type == 0 || s != 0)
2079 p->selection =
false;
2080 p->cselection =
false;
2089 mSelRange = p->selectionRange;
2093 line = p->commandLineLineBySerial(l);
2094 mSelRange = p->cselectionRange;
2097 if(c >= line.length() || line.at(c).isSpace())
2099 p->selection =
false;
2100 p->cselection =
false;
2105 if(mSelRange == NULL)
2113 if(line.at(i).isSpace())
2119 mSelRange[3] = line.length();
2120 for(i=c;i<line.length();++i)
2121 if(line.at(i).isSpace())
2127 p->selection = type == 1 ?
true :
false;
2128 p->cselection = type == 2 ?
true :
false;
2132 HConsoleLine* HConsolePanelPrivate::commandLineObjectBySerial(
int serial)
2134 HConsoleLine* r = cfirst;
2139 if(r->serial == serial)
2146 QString HConsolePanelPrivate::commandLineLineBySerial(
int serial)
2148 HConsoleLine* r = commandLineObjectBySerial(serial);
2154 void HConsolePanelPrivate::setCommandLineLineBySerial(
int serial,QString newtext)
2156 HConsoleLine* r = cfirst;
2161 if(r->serial == serial)
2172 p->cfirst->line =
"";
2173 HConsoleLine *todel=NULL,*cr = p->cfirst->next;
2180 p->cfirst->next = NULL;
2181 p->ctop = p->clast = p->cfirst;
2182 p->cfirst->autole =
true;
2183 p->cursorPos[0] = p->cfirst->serial;
2184 p->cursorPos[1] = 0;
2185 p->origCursorPos2 = p->cursorPos[1];
2196 if(t.contains(
"\n"))
2198 QStringList lines = t.split(
"\n");
2199 QList<QString>::iterator i=lines.begin();
2200 for(;i!=lines.end();++i)
2201 p->addCommandLineTextPart(*i,
true);
2204 p->addCommandLineTextPart(t,
true);
2206 p->cursorPos[0] = p->clast->serial;
2207 p->cursorPos[1] = p->clast->line.length();
2208 p->origCursorPos2 = p->cursorPos[1];
2216 void HConsolePanelPrivate::addCommandLineTextPart(QString t,
bool hardend)
2218 stringReplaceTabToSpace(t);
2219 if(maxLineLength < calcStringWidth( (cfirst == clast && cfirst->line.isEmpty() ? promptStr : QString()) + t ))
2221 int s = calcStringBreakPos( (cfirst == clast && cfirst->line.isEmpty() ? promptStr : QString()) + t );
2222 s -= (cfirst == clast && cfirst->line.isEmpty() ? promptStr.length() : 0);
2223 addCommandLineLine(t.left(s),
false);
2224 addCommandLineTextPart(t.mid(s,-1),hardend);
2227 addCommandLineLine(t,hardend);
2230 void HConsolePanelPrivate::addCommandLineLine(QString t,
bool hardend)
2232 if(cfirst->next == NULL && cfirst == clast && cfirst->line.isEmpty())
2235 cfirst->autole = !hardend;
2239 clast =
new HConsoleLine(t,clast);
2241 clast->autole =
false;
2247 QString c = QString();
2248 HConsoleLine* cr = p->cfirst;
2251 c += cr->line + ((cr->next != NULL && !cr->autole) ?
"\n" :
"");
2260 HConsoleLine* cr = p->cfirst;
2263 if(p->cursorPos[0] > cr->serial)
2264 cp += ( cr->line.length() + (cr->autole ? 0 : 1) );
2265 if(p->cursorPos[0] == cr->serial)
2266 return cp + p->cursorPos[1];
2276 HConsoleLine* cr = p->cfirst;
2279 if(c > cr->line.length())
2280 c -= ( cr->line.length() + (cr->autole ? 0 : 1) );
2283 p->cursorPos[0] = cr->serial;
2284 p->cursorPos[1] = c;
2285 p->origCursorPos2 = p->cursorPos[1];
2295 if(p->cursorPos[0] == p->clast->serial &&
2296 !text.contains(
"\n") &&
2297 !text.contains(
"\t") &&
2299 p->maxLineLength > p->calcStringWidth(
2300 (p->cursorPos[0] == p->cfirst->serial ? p->promptStr : QString()) +
2301 p->clast->line + text )
2305 if(p->cursorPos[1] == p->clast->line.length())
2306 p->clast->line.append(text);
2308 p->clast->line.insert(p->cursorPos[1],text);
2310 p->clast->width = p->calcStringWidth(p->clast->line);
2311 p->cursorPos[1] += text.length();
2312 p->origCursorPos2 = p->cursorPos[1];
2326 p->cselection =
false;
2339 if(p->cursorPos[0] == p->clast->serial)
2341 if(p->cfirst == p->clast && p->clast->line.isEmpty())
2344 if(!forwardDel && p->cursorPos[1] > 0)
2346 p->clast->line.remove(p->cursorPos[1]-1,1);
2347 p->cursorPos[1] = p->cursorPos[1] - 1;
2348 p->origCursorPos2 = p->cursorPos[1];
2354 if(p->cursorPos[1] >= p->clast->line.length())
2356 p->clast->line.remove(p->cursorPos[1],1);
2357 p->origCursorPos2 = p->cursorPos[1];
2368 if(!forwardDel && abs > 0)
2374 if(forwardDel && abs < c.length())
2390 c = p->cmdLineTextSkipsel(abs);
2394 p->cselection =
false;
2403 p->cselection =
false;
2405 if(inSelection && !p->cselection)
2407 p->cselectionRange[0] = p->cursorPos[0];
2408 p->cselectionRange[1] = p->cursorPos[1];
2409 p->cselectionRange[4] = p->cursorPos[0];
2410 p->cselectionRange[5] = p->cursorPos[1];
2413 for(;charCount > 0;--charCount)
2415 if(p->cursorPos[1] > 0)
2419 else if(p->cursorPos[0] > p->cfirst->serial)
2422 l = p->commandLineObjectBySerial(p->cursorPos[0]);
2423 p->cursorPos[1] = l == NULL ? 0 : l->line.length();
2427 p->origCursorPos2 = p->cursorPos[1];
2431 if(p->cselectionRange[4] < p->cursorPos[0] ||
2432 (p->cselectionRange[4] == p->cursorPos[0] && p->cselectionRange[5] < p->cursorPos[1]))
2434 p->cselectionRange[2] = p->cursorPos[0];
2435 p->cselectionRange[3] = p->cursorPos[1];
2436 p->cselectionRange[0] = p->cselectionRange[4];
2437 p->cselectionRange[1] = p->cselectionRange[5];
2441 p->cselectionRange[0] = p->cursorPos[0];
2442 p->cselectionRange[1] = p->cursorPos[1];
2443 p->cselectionRange[2] = p->cselectionRange[4];
2444 p->cselectionRange[3] = p->cselectionRange[5];
2446 p->cselection =
true;
2447 p->selection =
false;
2458 p->cselection =
false;
2460 if(inSelection && !p->cselection)
2462 p->cselectionRange[0] = p->cursorPos[0];
2463 p->cselectionRange[1] = p->cursorPos[1];
2464 p->cselectionRange[4] = p->cursorPos[0];
2465 p->cselectionRange[5] = p->cursorPos[1];
2468 for(;charCount > 0;--charCount)
2470 l = p->commandLineObjectBySerial(p->cursorPos[0]);
2473 if(p->cursorPos[0] == p->clast->serial)
2475 if(p->cursorPos[1] < l->line.length())
2482 if(p->cursorPos[1] < l->line.length())
2489 p->cursorPos[1] = 0;
2494 p->origCursorPos2 = p->cursorPos[1];
2498 if(p->cselectionRange[4] < p->cursorPos[0] ||
2499 (p->cselectionRange[4] == p->cursorPos[0] && p->cselectionRange[5] < p->cursorPos[1]))
2501 p->cselectionRange[2] = p->cursorPos[0];
2502 p->cselectionRange[3] = p->cursorPos[1];
2503 p->cselectionRange[0] = p->cselectionRange[4];
2504 p->cselectionRange[1] = p->cselectionRange[5];
2508 p->cselectionRange[0] = p->cursorPos[0];
2509 p->cselectionRange[1] = p->cursorPos[1];
2510 p->cselectionRange[2] = p->cselectionRange[4];
2511 p->cselectionRange[3] = p->cselectionRange[5];
2513 p->cselection =
true;
2514 p->selection =
false;
2520 QString HConsolePanelPrivate::cmdLineTextSkipsel(
int& new_cursor_pos)
2523 return pp->commandLineText();
2528 HConsoleLine* r = cfirst;
2531 if(cselectionRange[0] == r->serial && cselectionRange[2] == r->serial)
2534 ss=cselectionRange[1];
2537 ee = cselectionRange[3];
2538 if(ee > r->line.length())
2539 ee = r->line.length();
2541 c += r->line.left(ss);
2542 c += r->line.mid(ee,-1) + ((r->next != NULL && !r->autole) ?
"\n" :
"");
2543 new_cursor_pos += r->line.left(ss).length();
2546 else if(cselectionRange[0] == r->serial)
2548 int ss = cselectionRange[1];
2551 c += r->line.left(ss);
2552 new_cursor_pos += r->line.left(ss).length();
2555 else if(cselectionRange[0] < r->serial && cselectionRange[2] > r->serial)
2559 else if(cselectionRange[2] == r->serial)
2561 int ee = cselectionRange[3];
2562 if(ee > r->line.length())
2563 ee = r->line.length();
2565 c += r->line.mid(ee,-1) + ((r->next != NULL && !r->autole) ?
"\n" :
"");
2570 new_cursor_pos += ( r->line.length() + (r->autole ? 0 : 1) );
2571 c += r->line + ((r->next != NULL && !r->autole) ?
"\n" :
"");
2580 const QClipboard *clipboard = QApplication::clipboard();
2581 const QMimeData *mimeData = clipboard->mimeData();
2586 void HConsolePanel::wheelEvent(QWheelEvent *e)
2590 if(p->first == NULL)
2592 p->getLCfromXY(e->x(),e->y(),l,c,scroll,t);
2593 if(t == 2 && p->cfirst != p->clast)
2596 if(e->delta()>0 && p->cursorPos[0] > p->cfirst->serial)
2597 p->cursorPos[0] -= 1;
2598 if(e->delta()<0 && p->cursorPos[0] < p->clast->serial)
2599 p->cursorPos[0] += 1;
2601 p->cursorPos[1] = p->origCursorPos2;
2602 if(p->cursorPos[1] > p->commandLineLineBySerial(p->cursorPos[0]).length())
2603 p->cursorPos[1] = p->commandLineLineBySerial(p->cursorPos[0]).length();
2610 scrollDown(e->modifiers() == Qt::ShiftModifier ? 10 : 1);
2612 scrollUp(e->modifiers() == Qt::ShiftModifier ? 10 : 1);
2616 void HConsolePanel::keyPressEvent(QKeyEvent *e)
2618 if(e->key() == Qt::Key_PageUp && e->modifiers() == Qt::ShiftModifier)
2623 if(e->key() == Qt::Key_PageDown && e->modifiers() == Qt::ShiftModifier)
2629 if(e->key() == Qt::Key_A && e->modifiers() == Qt::ControlModifier)
2635 if((e->key() == Qt::Key_Insert && e->modifiers() == Qt::ControlModifier) ||
2636 (e->key() == Qt::Key_C && e->modifiers() == Qt::ControlModifier))
2642 if((e->key() == Qt::Key_Insert && e->modifiers() == Qt::ShiftModifier) ||
2643 (e->key() == Qt::Key_V && e->modifiers() == Qt::ControlModifier))
2649 if(e->key() == Qt::Key_Home)
2651 if(p->cfirst == p->clast && p->cfirst->line.isEmpty() && p->first != p->top)
2653 p->viewtop = p->first;
2658 if(e->modifiers() == Qt::ShiftModifier)
2660 p->cselectionRange[2] = p->cursorPos[0];
2661 p->cselectionRange[3] = p->cursorPos[1];
2662 p->cselectionRange[4] = p->cselectionRange[0];
2663 p->cselectionRange[5] = p->cselectionRange[1];
2666 p->selection =
false;
2667 p->cselection =
false;
2668 p->cursorPos[1] = 0;
2669 if(e->modifiers() == Qt::ShiftModifier)
2671 p->cselectionRange[0] = p->cursorPos[0];
2672 p->cselectionRange[1] = p->cursorPos[1];
2673 if(p->cselectionRange[1] != p->cselectionRange[3])
2674 p->cselection =
true;
2680 if(e->key() == Qt::Key_End)
2682 if(p->cfirst == p->clast && p->cfirst->line.isEmpty() && p->viewtop != NULL)
2689 if(e->modifiers() == Qt::ShiftModifier)
2691 p->cselectionRange[0] = p->cursorPos[0];
2692 p->cselectionRange[1] = p->cursorPos[1];
2693 p->cselectionRange[4] = p->cselectionRange[0];
2694 p->cselectionRange[5] = p->cselectionRange[1];
2697 p->selection =
false;
2698 p->cselection =
false;
2699 p->cursorPos[1] = p->commandLineLineBySerial(p->cursorPos[0]).length();
2700 if(e->modifiers() == Qt::ShiftModifier)
2702 p->cselectionRange[2] = p->cursorPos[0];
2703 p->cselectionRange[3] = p->cursorPos[1];
2704 if(p->cselectionRange[1] != p->cselectionRange[3])
2705 p->cselection =
true;
2712 if(e->key() == Qt::Key_Escape)
2715 p->selection =
false;
2716 p->cselection =
false;
2718 p->history_it = p->history.end();
2724 if(e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete)
2732 if(e->key() == Qt::Key_Up)
2736 p->cselection =
false;
2737 if(!p->history.isEmpty())
2739 if(p->history_it == p->history.end())
2741 p->history_it = p->history.end();
2746 if(p->history_it != p->history.begin())
2754 if(e->key() == Qt::Key_Down)
2758 p->cselection =
false;
2759 if(!p->history.isEmpty() && p->history_it != p->history.end())
2762 if(p->history_it == p->history.end())
2773 if(e->key() == Qt::Key_Left)
2775 cursorLeft(1,e->modifiers() == Qt::ShiftModifier ?
true :
false);
2779 if(e->key() == Qt::Key_Right)
2781 cursorRight(1,e->modifiers() == Qt::ShiftModifier ?
true :
false);
2785 if(e->key() == Qt::Key_B && e->modifiers() == Qt::ControlModifier)
2791 if(e->key() == Qt::Key_S && e->modifiers() == Qt::ControlModifier)
2797 if(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter)
2799 if(e->modifiers() == Qt::ShiftModifier)
2808 if(!send.isEmpty() && (p->history.isEmpty() || send != p->history.last()))
2810 p->history.push_back(send);
2811 p->history_it = p->history.end();
2819 if(e->key() == Qt::Key_Shift || e->key() == Qt::Key_Alt || e->key() == Qt::Key_Control)
2823 if(e->modifiers() != Qt::ControlModifier && e->modifiers() != Qt::AltModifier)
2831 bool HConsolePanel::event(QEvent *e)
2833 if(e->type() == QEvent::KeyPress)
2835 QKeyEvent *ke =
static_cast<QKeyEvent *
>(e);
2836 if(ke->key() == Qt::Key_Tab)
2845 if((ke->key() == Qt::Key_Plus && ke->modifiers() == Qt::ControlModifier) ||
2846 (ke->key() == Qt::Key_Plus && ke->modifiers() == (Qt::ControlModifier | Qt::KeypadModifier)))
2851 if((ke->key() == Qt::Key_Minus && ke->modifiers() == Qt::ControlModifier) ||
2852 (ke->key() == Qt::Key_Minus && ke->modifiers() == (Qt::ControlModifier | Qt::KeypadModifier)))
2857 if((ke->key() == Qt::Key_0 && ke->modifiers() == Qt::ControlModifier) ||
2858 (ke->key() == Qt::Key_0 && ke->modifiers() == (Qt::ControlModifier | Qt::KeypadModifier)))
2864 return QWidget::event(e);
2875 return p->promptStr;
2880 p->fontsize = point;
2882 f.setPixelSize(p->fontsize);
2885 p->fm =
new QFontMetrics(font(),
this);
2894 void HConsolePanel::biggerFontSize(
void)
2902 void HConsolePanel::smallerFontSize(
void)
2910 void HConsolePanel::normalFontSize(
void)
2915 #endif //GSAFE_DISABLE_DEBUG
void commandEntered(QString commandText)
static HDebugConsole * myself
void deleteCmdLineSelection(void)
static void popup(QString title, QString str)
void deleteFromCursor(bool forwardDel=false)
HConsolePanel * consoleObject(void)
void unregister_dconsole_command(QString command)
void setCommandLineCharacterEcho(bool disable=false)
QString commandLineText(void)
void setMarginText(QString margin)
void dconsole_close(void)
void pasteToCommandLine(void)
void cursorLeft(int charCount=1, bool inSelection=false)
void addTextToCursor(QString text)
void setTextTypeColor(char type, QColor color)
void scrollUp(int lineCount=1)
void setTabStop(int count)
HDebugConsole(QWidget *parent)
void setCursorPosition(int c)
void clearSelection(void)
void setPromptString(QString prm)
HConsolePanel(QWidget *parent)
QString promptString(void)
void setCommandLineText(QString t, bool disableupdate=false)
void resetCommandLine(void)
void add_text(QString s, int type)
QString selectedText(void)
virtual QString donsole_command_interpreter(QString commandString)=0
void setColor(QString section, QColor color)
void register_dconsole_command(QString command, HDConsoleCommandHolder *interpreter, QString descr)
void addNormalText(QString text)
void setFontSize(int point)
void cursorRight(int charCount=1, bool inSelection=false)
void tabPressed(QString commandText)
void scrollDown(int lineCount=1)
void dconsole_popup(QString t, QString txt)
static void debug_txt(QString s)
void setCommandExecution(bool enabled=true)
void scrollToSerial(int serial)
void addText(QString t, char type=0)
static void debug_sql(QString s)
QString lineBySerial(int serial, bool withWraps=false, bool onDisplay=true)
void clear_dconsole_commands()