#include <KLocalizedString>
#include <QDragEnterEvent>
+#include <QInputDialog>
#include <QMenu>
#include <QMimeData>
#include <QTimer>
+class PreventFocusWhileHidden : public QObject
+{
+public:
+ PreventFocusWhileHidden(QObject *parent)
+ : QObject(parent){};
+
+protected:
+ bool eventFilter(QObject *obj, QEvent *ev) override
+ {
+ switch (ev->type()) {
+ case QEvent::Hide:
+ static_cast<QWidget *>(obj)->setFocusPolicy(Qt::NoFocus);
+ return false;
+ case QEvent::Show:
+ static_cast<QWidget *>(obj)->setFocusPolicy(Qt::TabFocus);
+ return false;
+ default:
+ return false;
+ }
+ };
+};
+
DolphinTabBar::DolphinTabBar(QWidget *parent)
: QTabBar(parent)
, m_autoActivationIndex(-1)
setMovable(true);
setTabsClosable(true);
+ setFocusPolicy(Qt::NoFocus);
+ installEventFilter(new PreventFocusWhileHidden(this));
+
m_autoActivationTimer = new QTimer(this);
m_autoActivationTimer->setSingleShot(true);
m_autoActivationTimer->setInterval(800);
void DolphinTabBar::dragEnterEvent(QDragEnterEvent *event)
{
const QMimeData *mimeData = event->mimeData();
- const int index = tabAt(event->pos());
+ const int index = tabAt(event->position().toPoint());
if (mimeData->hasUrls()) {
event->acceptProposedAction();
void DolphinTabBar::dragMoveEvent(QDragMoveEvent *event)
{
const QMimeData *mimeData = event->mimeData();
- const int index = tabAt(event->pos());
+ const int index = tabAt(event->position().toPoint());
if (mimeData->hasUrls()) {
+ Q_EMIT tabDragMoveEvent(index, event);
updateAutoActivationTimer(index);
}
updateAutoActivationTimer(-1);
const QMimeData *mimeData = event->mimeData();
- const int index = tabAt(event->pos());
+ const int index = tabAt(event->position().toPoint());
if (mimeData->hasUrls()) {
Q_EMIT tabDropEvent(index, event);
void DolphinTabBar::mouseDoubleClickEvent(QMouseEvent *event)
{
- int index = tabAt(event->pos());
+ if (event->buttons() & Qt::LeftButton) {
+ int index = tabAt(event->pos());
- if (index < 0) {
- // empty tabbar area case
- index = currentIndex();
+ if (index < 0) {
+ // empty tabbar area case
+ index = currentIndex();
+ }
+ // Double left click on the tabbar opens a new activated tab
+ // with the url from the doubleclicked tab or currentTab otherwise.
+ Q_EMIT openNewActivatedTab(index);
}
- // Double click on the tabbar opens a new activated tab
- // with the url from the doubleclicked tab or currentTab otherwise.
- Q_EMIT openNewActivatedTab(index);
QTabBar::mouseDoubleClickEvent(event);
}
QAction *closeOtherTabsAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-close-other")), i18nc("@action:inmenu", "Close Other Tabs"));
QAction *closeTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-close")), i18nc("@action:inmenu", "Close Tab"));
+ QAction *renameTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-rename")), i18nc("@action:inmenu", "Rename Tab"));
+
QAction *selectedAction = menu.exec(event->globalPos());
if (selectedAction == newTabAction) {
Q_EMIT openNewActivatedTab(index);
}
} else if (selectedAction == closeTabAction) {
Q_EMIT tabCloseRequested(index);
+ } else if (selectedAction == renameTabAction) {
+ bool renamed = false;
+ const QString tabNewName = QInputDialog::getText(this, i18nc("@title:window for text input", "Rename Tab"), i18n("New tab name:"), QLineEdit::Normal, tabText(index), &renamed);
+
+ if (renamed) {
+ Q_EMIT tabRenamed(index, tabNewName);
+ }
}
return;