59
59
#include "../ActionMan/addplaceholderpopup.h"
60
60
#include "kcmdmodebutton.h"
63
CmdLineCombo::CmdLineCombo(QWidget *parent) : KHistoryComboBox(parent), _handlingLineEditResize(false)
65
lineEdit()->installEventFilter(this);
66
_pathLabel = new QLabel(this);
67
_pathLabel->setWhatsThis(i18n("Name of directory where command will be processed."));
68
_pathLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
71
bool CmdLineCombo::eventFilter(QObject *watched, QEvent *e)
73
if(watched == lineEdit() && (e->type() == QEvent::Move || e->type() == QEvent::Resize)) {
74
if(!_handlingLineEditResize) { // avoid infinite recursion
75
_handlingLineEditResize = true;
76
updateLineEditGeometry();
77
_handlingLineEditResize = false;
83
void CmdLineCombo::setPath(QString path)
89
void CmdLineCombo::updateLineEditGeometry()
91
QRect r = lineEdit()->geometry();
92
r.setLeft(_pathLabel->geometry().right());
93
lineEdit()->setGeometry(r);
96
void CmdLineCombo::doLayout()
98
QString pathNameLabel = _path;
99
QFontMetrics fm(_pathLabel->fontMetrics());
100
int textWidth = fm.width(_path);
101
int maxWidth = (width() + _pathLabel->width()) * 2 / 5;
102
int letters = _path.length() / 2;
104
while (letters && textWidth > maxWidth) {
105
pathNameLabel = _path.left(letters) + "..." + _path.right(letters);
107
textWidth = fm.width(pathNameLabel);
110
_pathLabel->setText(pathNameLabel + "> ");
111
_pathLabel->adjustSize();
113
QStyleOptionComboBox opt;
114
initStyleOption(&opt);
115
QRect labelRect = style()->subControlRect(QStyle::CC_ComboBox, &opt,
116
QStyle::SC_ComboBoxEditField, this);
117
labelRect.adjust(2, 0, 0, 0);
118
labelRect.setWidth(_pathLabel->width());
119
_pathLabel->setGeometry(labelRect);
121
updateLineEditGeometry();
124
void CmdLineCombo::resizeEvent(QResizeEvent *e)
126
KHistoryComboBox::resizeEvent(e);
130
void CmdLineCombo::keyPressEvent(QKeyEvent *e)
135
if (e->modifiers() & Qt::ControlModifier) {
136
SLOTS->insertFileName((e->modifiers() & Qt::ShiftModifier) != 0);
139
KHistoryComboBox::keyPressEvent(e);
142
if (e->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
143
MAIN_VIEW->focusTerminalEmulator();
146
KHistoryComboBox::keyPressEvent(e);
149
if (e->modifiers() == Qt::ControlModifier || e->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
150
emit returnToPanel();
153
KHistoryComboBox::keyPressEvent(e);
156
if (e->modifiers() == 0) {
157
emit returnToPanel();
160
KHistoryComboBox::keyPressEvent(e);
163
KHistoryComboBox::keyPressEvent(e);
62
168
KCMDLine::KCMDLine(QWidget *parent) : QWidget(parent)
64
170
QGridLayout * layout = new QGridLayout(this);
65
171
layout->setSpacing(0);
66
172
layout->setContentsMargins(0, 0, 0, 0);
67
path = new QLabel(this);
68
path->setWhatsThis(i18n("Name of directory where command will be processed."));
69
path->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
70
path->setFrameStyle(QFrame::Box | QFrame::Sunken);
71
path->setLineWidth(1);
72
path->setFont(KGlobalSettings::generalFont());
73
174
int height = QFontMetrics(KGlobalSettings::generalFont()).height();
74
175
height = height + 5 * (height > 14) + 6;
75
path->setMaximumHeight(height);
76
path->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred));
77
layout->addWidget(path, 0, 0);
79
177
// and editable command line
80
178
completion.setMode(KUrlCompletion::FileCompletion);
81
cmdLine = new KrHistoryCombo(this);
179
cmdLine = new CmdLineCombo(this);
82
180
cmdLine->setMaxCount(100); // remember 100 commands
83
181
cmdLine->setMinimumContentsLength(10);
84
182
cmdLine->setDuplicatesEnabled(false);
132
230
this->addText(exp);
135
void KCMDLine::setCurrent(const QString &p)
233
void KCMDLine::setCurrent(const QString &path)
235
cmdLine->setPath(path);
140
completion.setDir(p);
237
completion.setDir(path);
141
238
// make sure our command is executed in the right directory
142
239
// This line is important for Krusader overall functions -> do not remove !
146
void KCMDLine::calcLabelSize()
148
QString pathNameLabel = pathName;
149
QFontMetrics fm(path->fontMetrics());
150
int textWidth = fm.width(pathName);
151
int maxWidth = (cmdLine->width() + path->width()) * 2 / 5;
152
int letters = pathName.length() / 2;
154
while (letters && textWidth > maxWidth) {
155
pathNameLabel = pathName.left(letters) + "..." + pathName.right(letters);
157
textWidth = fm.width(pathNameLabel);
160
path->setText(pathNameLabel + '>');
240
QDir::setCurrent(path);
163
243
void KCMDLine::slotRun()
245
325
cmdLine->lineEdit()->setText(text);
249
void KrHistoryCombo::keyPressEvent(QKeyEvent *e)
254
if (e->modifiers() & Qt::ControlModifier) {
255
SLOTS->insertFileName((e->modifiers() & Qt::ShiftModifier) != 0);
258
KHistoryComboBox::keyPressEvent(e);
261
if (e->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
262
MAIN_VIEW->focusTerminalEmulator();
265
KHistoryComboBox::keyPressEvent(e);
268
if (e->modifiers() == Qt::ControlModifier || e->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
269
emit returnToPanel();
272
KHistoryComboBox::keyPressEvent(e);
275
if (e->modifiers() == 0) {
276
emit returnToPanel();
279
KHistoryComboBox::keyPressEvent(e);
282
KHistoryComboBox::keyPressEvent(e);
286
#include "kcmdline.moc"