~lxqt/lxqt/qterminal

« back to all changes in this revision

Viewing changes to src/tabwidget.cpp

  • Committer: Jörn Schönyan
  • Date: 2016-10-21 06:40:10 UTC
  • Revision ID: joern.schoenyan@web.de-20161021064010-2oqdifitpqk0lrrm
v0.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
 
30
30
#define TAB_INDEX_PROPERTY "tab_index"
 
31
#define TAB_CUSTOM_NAME_PROPERTY "custom_name"
31
32
 
32
33
 
33
34
TabWidget::TabWidget(QWidget* parent) : QTabWidget(parent), tabNumerator(0)
78
79
    }
79
80
 
80
81
    TermWidgetHolder *console = new TermWidgetHolder(cwd, shell_program, this);
 
82
    console->setWindowTitle(label);
81
83
    connect(console, SIGNAL(finished()), SLOT(removeFinished()));
82
84
    connect(console, SIGNAL(lastTerminalClosed()), this, SLOT(removeFinished()));
 
85
    connect(console, &TermWidgetHolder::termTitleChanged, this, &TabWidget::onTermTitleChanged);
 
86
    connect(this, &QTabWidget::currentChanged, this, &TabWidget::currentTitleChanged);
83
87
 
84
88
    int index = addTab(console, label);
 
89
    console->setProperty(TAB_CUSTOM_NAME_PROPERTY, false);
85
90
    updateTabIndices();
86
91
    setCurrentIndex(index);
87
92
    console->setInitialFocus();
152
157
        widget(i)->setProperty(TAB_INDEX_PROPERTY, i);
153
158
}
154
159
 
 
160
void TabWidget::onTermTitleChanged(QString title, QString icon)
 
161
{
 
162
    TermWidgetHolder * console = qobject_cast<TermWidgetHolder*>(sender());
 
163
    const bool custom_name = console->property(TAB_CUSTOM_NAME_PROPERTY).toBool();
 
164
    if (!custom_name)
 
165
    {
 
166
        const int index = console->property(TAB_INDEX_PROPERTY).toInt();
 
167
 
 
168
        setTabIcon(index, QIcon::fromTheme(icon));
 
169
        setTabText(index, title);
 
170
        if (currentIndex() == index)
 
171
            emit currentTitleChanged(index);
 
172
    }
 
173
}
 
174
 
155
175
void TabWidget::renameSession(int index)
156
176
{
157
177
    bool ok = false;
160
180
                                        QString(), &ok);
161
181
    if(ok && !text.isEmpty())
162
182
    {
 
183
        setTabIcon(index, QIcon{});
163
184
        setTabText(index, text);
 
185
        widget(index)->setProperty(TAB_CUSTOM_NAME_PROPERTY, true);
 
186
        if (currentIndex() == index)
 
187
            emit currentTitleChanged(index);
164
188
    }
165
189
}
166
190
 
 
191
void TabWidget::renameCurrentSession()
 
192
{
 
193
    renameSession(currentIndex());
 
194
}
 
195
 
167
196
void TabWidget::renameTabsAfterRemove()
168
197
{
169
198
// it breaks custom names - it replaces original/custom title with shell no #
174
203
#endif
175
204
}
176
205
 
177
 
void TabWidget::contextMenuEvent ( QContextMenuEvent * event )
 
206
void TabWidget::contextMenuEvent(QContextMenuEvent *event)
178
207
{
179
208
    QMenu menu(this);
180
209
 
181
210
    QAction *close = menu.addAction(QIcon::fromTheme("document-close"), tr("Close session"));
182
 
    QAction *rename = menu.addAction(tr("Rename session"));
183
 
    rename->setShortcut(tr(RENAME_SESSION_SHORTCUT));
 
211
    QAction *rename = menu.addAction(Properties::Instance()->actions[RENAME_SESSION]->text());
 
212
    rename->setShortcut(Properties::Instance()->actions[RENAME_SESSION]->shortcut());
 
213
    rename->blockSignals(true);
184
214
 
185
215
    int tabIndex = tabBar()->tabAt(event->pos());
186
216
    QAction *action = menu.exec(event->globalPos());
332
362
    if(!scrollPosition)
333
363
        qFatal("scrollPosition is NULL");
334
364
 
335
 
 
336
365
    Properties::Instance()->scrollBarPos =
337
366
            scrollPosition->actions().indexOf(triggered);
338
367
 
353
382
    setTabPosition(position);
354
383
    prop->tabsPos = position;
355
384
    prop->saveSettings();
356
 
    return;
 
385
}
 
386
 
 
387
void TabWidget::changeKeyboardCursorShape(QAction *triggered)
 
388
{
 
389
    QActionGroup *keyboardCursorShape = static_cast<QActionGroup *>(sender());
 
390
    if(!keyboardCursorShape)
 
391
        qFatal("keyboardCursorShape is NULL");
 
392
 
 
393
    Properties::Instance()->keyboardCursorShape =
 
394
            keyboardCursorShape->actions().indexOf(triggered);
 
395
 
 
396
    Properties::Instance()->saveSettings();
 
397
    propertiesChanged();
357
398
}
358
399
 
359
400
void TabWidget::propertiesChanged()