3 // Originally part of QCad Community Edition by Andrew Mustun
4 // Extensively rewritten and refactored by James L. Hammons
5 // (C) 2010 Underground Software
7 // JLH = James L. Hammons <jlhamm@acm.org>
10 // --- ---------- -----------------------------------------------------------
11 // JLH 05/12/2010 Created this file. :-)
14 #include "commandwidget.h"
17 #include "qg_actionhandler.h"
19 CommandWidget::CommandWidget(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
20 QWidget(parent, flags), actionHandler(NULL)
25 ui.leCommand->setFrame(false);
26 ui.leCommand->setFocusPolicy(Qt::StrongFocus);
30 CommandWidget::~CommandWidget()
34 bool CommandWidget::checkFocus()
36 return ui.leCommand->hasFocus();
39 void CommandWidget::setFocus()
42 ui.leCommand->setFocus();
45 void CommandWidget::setCommand(const QString & cmd)
48 ui.lCommand->setText(cmd);
50 ui.lCommand->setText(tr("Command:"));
52 ui.leCommand->setText("");
55 void CommandWidget::appendHistory(const QString & msg)
57 ui.teHistory->append(msg);
60 void CommandWidget::trigger()
62 QString cmd = ui.leCommand->text();
69 if (actionHandler != NULL)
70 actionHandler->command(cmd);
72 ui.leCommand->setText("");
75 void CommandWidget::tabPressed()
77 if (actionHandler != NULL)
79 QStringList reducedChoice;
80 QString typed = ui.leCommand->text();
83 // check current command:
84 choice = actionHandler->getAvailableCommands();
86 if (choice.count() == 0)
87 choice = RS_COMMANDS->complete(typed);
89 for(QStringList::Iterator it=choice.begin(); it!=choice.end(); ++it)
91 if (typed.isEmpty() || (*it).startsWith(typed))
92 reducedChoice << (*it);
96 if (reducedChoice.count() == 1)
97 ui.leCommand->setText(reducedChoice.first());
98 else if (reducedChoice.count() > 0)
99 appendHistory(reducedChoice.join(", "));
103 void CommandWidget::escape()
105 //leCommand->clearFocus();
107 if (actionHandler != NULL)
108 actionHandler->slotFocusNormal();
111 /*void CommandWidget::cmdChanged(const QString& text) {
112 // three equal letters enable hotkeys and move the focus away from the command line:
113 if (text.length()==3) {
114 if (text.at(0)==text.at(1) && text.at(0)==text.at(2)) {
120 void CommandWidget::setActionHandler(QG_ActionHandler * ah)
125 void CommandWidget::setCommandMode()
127 // ui.lCommand->setPaletteForegroundColor(Qt::blue);
129 palette.setColor(ui.lCommand->foregroundRole(), Qt::blue);
130 ui.lCommand->setPalette(palette);
133 void CommandWidget::setNormalMode()
135 // ui.lCommand->setPaletteForegroundColor(Qt::black);
137 palette.setColor(ui.lCommand->foregroundRole(), Qt::black);
138 ui.lCommand->setPalette(palette);