3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/12/2010 Created this file. :-)
17 #include "commandwidget.h"
20 #include "actionhandler.h"
22 CommandWidget::CommandWidget(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
23 QWidget(parent, flags), actionHandler(NULL)
28 ui.leCommand->setFrame(false);
29 ui.leCommand->setFocusPolicy(Qt::StrongFocus);
33 CommandWidget::~CommandWidget()
37 bool CommandWidget::checkFocus()
39 return ui.leCommand->hasFocus();
42 void CommandWidget::setFocus()
45 ui.leCommand->setFocus();
48 void CommandWidget::setCommand(const QString & cmd)
51 ui.lCommand->setText(cmd);
53 ui.lCommand->setText(tr("Command:"));
55 ui.leCommand->setText("");
58 void CommandWidget::appendHistory(const QString & msg)
60 ui.teHistory->append(msg);
63 void CommandWidget::trigger()
65 QString cmd = ui.leCommand->text();
72 if (actionHandler != NULL)
73 actionHandler->command(cmd);
75 ui.leCommand->setText("");
78 void CommandWidget::tabPressed()
80 if (actionHandler != NULL)
82 QStringList reducedChoice;
83 QString typed = ui.leCommand->text();
86 // check current command:
87 choice = actionHandler->getAvailableCommands();
89 if (choice.count() == 0)
90 choice = COMMANDS->complete(typed);
92 for(QStringList::Iterator it=choice.begin(); it!=choice.end(); ++it)
94 if (typed.isEmpty() || (*it).startsWith(typed))
95 reducedChoice << (*it);
99 if (reducedChoice.count() == 1)
100 ui.leCommand->setText(reducedChoice.first());
101 else if (reducedChoice.count() > 0)
102 appendHistory(reducedChoice.join(", "));
106 void CommandWidget::escape()
108 //leCommand->clearFocus();
110 if (actionHandler != NULL)
111 actionHandler->slotFocusNormal();
114 /*void CommandWidget::cmdChanged(const QString& text) {
115 // three equal letters enable hotkeys and move the focus away from the command line:
116 if (text.length()==3) {
117 if (text.at(0)==text.at(1) && text.at(0)==text.at(2)) {
123 void CommandWidget::setActionHandler(ActionHandler * ah)
128 void CommandWidget::setCommandMode()
130 // ui.lCommand->setPaletteForegroundColor(Qt::blue);
132 palette.setColor(ui.lCommand->foregroundRole(), Qt::blue);
133 ui.lCommand->setPalette(palette);
136 void CommandWidget::setNormalMode()
138 // ui.lCommand->setPaletteForegroundColor(Qt::black);
140 palette.setColor(ui.lCommand->foregroundRole(), Qt::black);
141 ui.lCommand->setPalette(palette);