54
54
selectionLength(-1),
61
bool userIsHighlighting;
58
selectionType(Parser::Text)
62
bool userIsHighlighting;
72
Parser::Type selectionType;
72
AdvancedRenameInput::AdvancedRenameInput(QWidget* parent)
73
: KLineEdit(parent), d(new AdvancedRenameInputPriv)
75
AdvancedRenameLineEdit::AdvancedRenameLineEdit(QWidget* parent)
76
: KLineEdit(parent), d(new AdvancedRenameLineEditPriv)
78
d->curCursorPos = cursorPosition();
75
80
setFocusPolicy(Qt::StrongFocus);
76
81
setClearButtonShown(true);
77
setCompletionMode(KGlobalSettings::CompletionAuto);
78
setClickMessage(i18n("Enter renaming string (without extension)"));
82
setClickMessage(i18n("Enter renaming string"));
79
83
setToolTip(i18n("<p>Hold CTRL and move the mouse over the line edit widget to highlight token words.<br/>"
80
"Hold SHIFT and move the mouse to highlight tokens and its modifiers.<br/>"
84
"Hold SHIFT and move the mouse to highlight a token and its modifiers.<br/>"
81
85
"To mark a token, press the left mouse button while it is highlighted."
84
d->curCursorPos = cursorPosition();
86
88
// --------------------------------------------------------
88
90
d->parseTimer = new QTimer(this);
117
void AdvancedRenameInput::mouseMoveEvent(QMouseEvent* e)
119
void AdvancedRenameLineEdit::mouseMoveEvent(QMouseEvent* e)
119
121
KLineEdit::mouseMoveEvent(e);
120
122
int pos = cursorPositionAt(e->pos());
122
124
if (e->modifiers() == Qt::ControlModifier)
124
searchAndHighlightTokens(Token, pos);
126
searchAndHighlightTokens(Parser::Token, pos);
126
// else if ((e->modifiers() & (Qt::ControlModifier)) &&
127
// (e->modifiers())& (Qt::ShiftModifier))
129
// searchAndHighlightTokens(Modifier, pos);
131
128
else if (e->modifiers() & Qt::ShiftModifier)
133
searchAndHighlightTokens(TokenAndModifiers, pos);
130
searchAndHighlightTokens(Parser::TokenAndModifiers, pos);
135
132
else if (d->tokenMarked)
345
void AdvancedRenameInput::setSelectionColor(SelectionType type)
331
void AdvancedRenameLineEdit::setSelectionColor(Parser::Type type)
347
QString cssTemplate("QLineEdit { selection-background-color: %1; selection-color: %2;}");
333
QPalette p = palette();
353
css = cssTemplate.arg("red").arg("white");
356
css = cssTemplate.arg("green").arg("white");
358
case TokenAndModifiers:
359
css = cssTemplate.arg("yellow").arg("black");
362
css = cssTemplate.arg("palette(highlight)").arg("palette(highlighted-text)");
338
p.setColor(QPalette::Active, QPalette::Highlight, Qt::red);
339
p.setColor(QPalette::Active, QPalette::HighlightedText, Qt::white);
340
p.setColor(QPalette::Inactive, QPalette::Highlight, Qt::red);
341
p.setColor(QPalette::Inactive, QPalette::HighlightedText, Qt::white);
343
case Parser::TokenAndModifiers:
344
p.setColor(QPalette::Active, QPalette::Highlight, Qt::yellow);
345
p.setColor(QPalette::Active, QPalette::HighlightedText, Qt::black);
346
p.setColor(QPalette::Inactive, QPalette::Highlight, Qt::yellow);
347
p.setColor(QPalette::Inactive, QPalette::HighlightedText, Qt::black);
357
// --------------------------------------------------------
359
class AdvancedRenameInputPriv
363
AdvancedRenameInputPriv() :
364
configGroupName("AdvancedRename Input"),
365
configPatternHistoryListEntry("Pattern History List"),
372
const QString configGroupName;
373
const QString configPatternHistoryListEntry;
375
const int maxVisibleItems;
376
const int maxHistoryItems;
378
QStringList patternHistory;
380
AdvancedRenameLineEdit* lineEdit;
383
// --------------------------------------------------------
385
AdvancedRenameInput::AdvancedRenameInput(QWidget* parent)
386
: KComboBox(parent), d(new AdvancedRenameInputPriv)
388
// important: setEditable() has to be called before adding the actual line edit widget, otherwise
389
// our lineEdit gets removed again.
391
setMaxVisibleItems(d->maxVisibleItems);
392
setMaxCount(d->maxHistoryItems);
394
setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
396
d->lineEdit = new AdvancedRenameLineEdit(this);
397
setLineEdit(d->lineEdit);
399
connect(d->lineEdit, SIGNAL(signalTextChanged(const QString&)),
400
this, SIGNAL(signalTextChanged(const QString&)));
402
connect(d->lineEdit, SIGNAL(signalTokenMarked(bool)),
403
this, SIGNAL(signalTokenMarked(bool)));
408
AdvancedRenameInput::~AdvancedRenameInput()
414
void AdvancedRenameInput::setParser(Parser* parser)
416
d->lineEdit->setParser(parser);
419
void AdvancedRenameInput::slotAddToken(const QString& str)
421
d->lineEdit->slotAddToken(str);
424
void AdvancedRenameInput::slotAddModifier(const QString& str)
426
d->lineEdit->slotAddModifier(str);
429
void AdvancedRenameInput::readSettings()
431
KSharedConfig::Ptr config = KGlobal::config();
432
KConfigGroup group = config->group(d->configGroupName);
434
d->patternHistory = group.readEntry(d->configPatternHistoryListEntry, QStringList());
435
d->patternHistory.removeAll(QString(""));
436
addItems(d->patternHistory);
437
d->lineEdit->clear();
440
void AdvancedRenameInput::writeSettings()
442
KSharedConfig::Ptr config = KGlobal::config();
443
KConfigGroup group = config->group(d->configGroupName);
445
// remove duplicate entries and save pattern history, omit empty strings
446
QString pattern = d->lineEdit->text();
447
d->patternHistory.removeAll(pattern);
448
d->patternHistory.removeAll(QString(""));
449
d->patternHistory.prepend(pattern);
450
group.writeEntry(d->configPatternHistoryListEntry, d->patternHistory);
367
453
} // namespace Digikam