Tags: patch I completely forgot about this bug, sorry :) Maybe it's too obsolete now...
This patch changes the name of a bunch of variables (kde code is hard to understand), adds docs, and (to actually fix the bug), adds a signal itemSelected -> slotResetAffect... This resets the affect position pointer every time we select a new view so operations happen on the new view until the user makes a new right click. I also removed some calls to the reset function which are redundant now. This also fixes moving a tab after moving *to* a different tab using shift+arrow which I didn't notice in the original report.
diff --git a/yakuake/src/main_window.cpp b/yakuake/src/main_window.cpp index 7a15bde..62e8703 100644 --- a/yakuake/src/main_window.cpp +++ b/yakuake/src/main_window.cpp @@ -380,10 +380,9 @@ void MainWindow::slotRemoveSession(int session_id) void MainWindow::slotHandleRemoveSession(KAction::ActivationReason reason, Qt::ButtonState /* state */) { if (reason == KAction::PopupMenuActivation - && tab_bar->pressedPosition() != -1) + && tab_bar->affectPosition() != -1) { - slotRemoveSession(tab_bar->sessionIdForTabPosition(tab_bar->pressedPosition())); - tab_bar->resetPressedPosition(); + slotRemoveSession(tab_bar->sessionIdForTabPosition(tab_bar->affectPosition())); } else slotRemoveSession(); @@ -653,10 +652,9 @@ void MainWindow::windowActivationChange(bool old_active) void MainWindow::slotHandleHorizontalSplit(KAction::ActivationReason reason, Qt::ButtonState /* state */) { if (reason == KAction::PopupMenuActivation - && tab_bar->pressedPosition() != -1) + && tab_bar->affectPosition() != -1) { - slotSplitHorizontally(tab_bar->sessionIdForTabPosition(tab_bar->pressedPosition())); - tab_bar->resetPressedPosition(); + slotSplitHorizontally(tab_bar->sessionIdForTabPosition(tab_bar->affectPosition())); } else slotSplitHorizontally(); @@ -665,10 +663,9 @@ void MainWindow::slotHandleHorizontalSplit(KAction::ActivationReason reason, Qt: void MainWindow::slotHandleVerticalSplit(KAction::ActivationReason reason, Qt::ButtonState /* state */) { if (reason == KAction::PopupMenuActivation - && tab_bar->pressedPosition() != -1) + && tab_bar->affectPosition() != -1) { - slotSplitVertically(tab_bar->sessionIdForTabPosition(tab_bar->pressedPosition())); - tab_bar->resetPressedPosition(); + slotSplitVertically(tab_bar->sessionIdForTabPosition(tab_bar->affectPosition())); } else slotSplitVertically(); @@ -678,10 +675,9 @@ void MainWindow::slotHandleVerticalSplit(KAction::ActivationReason reason, Qt::B void MainWindow::slotHandleRemoveTerminal(KAction::ActivationReason reason, Qt::ButtonState /* state */) { if (reason == KAction::PopupMenuActivation - && tab_bar->pressedPosition() != -1) + && tab_bar->affectPosition() != -1) { - slotRemoveTerminal(tab_bar->sessionIdForTabPosition(tab_bar->pressedPosition())); - tab_bar->resetPressedPosition(); + slotRemoveTerminal(tab_bar->sessionIdForTabPosition(tab_bar->affectPosition())); } else slotRemoveTerminal(); @@ -1323,7 +1319,7 @@ void MainWindow::slotPollMouse() if (pos.y() == 0) { - if (Settings::screen() == 0) + if (Settings::screen() == 0) slotToggleState(); // no need to check x since yakuake should open where the mouse pointer is else if (pos.x() >= getDesktopGeometry().x() && pos.x() <= (getDesktopGeometry().x() + getDesktopGeometry().width())) slotToggleState(); diff --git a/yakuake/src/tab_bar.cpp b/yakuake/src/tab_bar.cpp index 72347db..52aa26b 100644 --- a/yakuake/src/tab_bar.cpp +++ b/yakuake/src/tab_bar.cpp @@ -21,7 +21,6 @@ #include <klocale.h> #include <kpopupmenu.h> - TabBar::TabBar(QWidget* parent, const char* name, bool translucency, const QString & skin) : TranslucentWidget(parent, name, translucency) { @@ -41,15 +40,9 @@ TabBar::~TabBar() delete minus_button; } -int TabBar::pressedPosition() -{ - return tabs_widget->pressedPosition(); -} - - -void TabBar::resetPressedPosition() +int TabBar::affectPosition() { - tabs_widget->resetPressedPosition(); + return tabs_widget->affectPosition(); } void TabBar::addItem(int session_id) diff --git a/yakuake/src/tab_bar.h b/yakuake/src/tab_bar.h index 6e8f3a0..2e05449 100644 --- a/yakuake/src/tab_bar.h +++ b/yakuake/src/tab_bar.h @@ -41,8 +41,8 @@ class TabBar : public TranslucentWidget void setSessionMenu(KPopupMenu* menu); - int pressedPosition(); - void resetPressedPosition(); + int affectPosition(); + // void resetAffectPosition(); void addItem(int session_id); int removeItem(int session_id); diff --git a/yakuake/src/tabbed_widget.cpp b/yakuake/src/tabbed_widget.cpp index c2b3961..46c4649 100644 --- a/yakuake/src/tabbed_widget.cpp +++ b/yakuake/src/tabbed_widget.cpp @@ -23,13 +23,12 @@ #include <kmainwindow.h> #include <kiconloader.h> - TabbedWidget::TabbedWidget(QWidget* parent, const char* name, bool translucency) : TranslucentWidget(parent, name, translucency) { - current_position = -1; pressed = false; - pressed_position = -1; + active_position = -1; + affect_position = -1; edited_position = -1; context_menu = 0; @@ -44,6 +43,7 @@ TabbedWidget::TabbedWidget(QWidget* parent, const char* name, bool translucency) inline_edit->hide(); connect(inline_edit, SIGNAL(returnPressed()), this, SLOT(slotRenameSelected())); + connect(this, SIGNAL(itemSelected(int)), this, SLOT(slotResetAffectPosition())); connect(inline_edit, SIGNAL(lostFocus()), inline_edit, SLOT(hide())); connect(inline_edit, SIGNAL(lostFocus()), this, SLOT(slotResetEditedPosition())); @@ -59,9 +59,14 @@ TabbedWidget::~TabbedWidget() delete context_menu; } -int TabbedWidget::pressedPosition() +void TabbedWidget::slotResetAffectPosition() +{ + resetAffectPosition(); +} + +int TabbedWidget::affectPosition() { - return pressed_position; + return affect_position; } void TabbedWidget::createContextMenu() @@ -148,18 +153,18 @@ int TabbedWidget::removeItem(int session_id) captions.remove(captions.at(position)); if (position != items.count()) - current_position = position; + active_position = position; else if (position != 0) - current_position = position - 1; + active_position = position - 1; else - current_position = -1; + active_position = -1; refreshBuffer(); - if (current_position != -1) - emit itemSelected(items[current_position]); + if (activePosition() != -1) + emit itemSelected(items[activePosition()]); - return current_position; + return activePosition(); } const QString TabbedWidget::itemName(int session_id) @@ -185,14 +190,14 @@ void TabbedWidget::renameItem(int session_id, const QString& namep) void TabbedWidget::interactiveRename() { - if (pressed_position != -1) + if (affectPosition() != -1) { - interactiveRename(pressed_position); - pressed_position = -1; + interactiveRename(affectPosition()); + affect_position = -1; } else { - interactiveRename(current_position); + interactiveRename(activePosition()); } } @@ -257,7 +262,7 @@ void TabbedWidget::selectItem(int session_id) if (new_position != -1) { - current_position = new_position; + active_position = new_position; refreshBuffer(); } } @@ -266,47 +271,49 @@ void TabbedWidget::selectPosition(int position) { if (position < int(items.count()) && !items.isEmpty()) { - current_position = position; + active_position = position; refreshBuffer(); - emit itemSelected(items[current_position]); + emit itemSelected(items[activePosition()]); } } void TabbedWidget::selectNextItem() { - if (current_position != int(items.count()) - 1) - current_position++; + if (activePosition() != int(items.count()) - 1) + active_position++; else - current_position = 0; + active_position = 0; refreshBuffer(); - emit itemSelected(items[current_position]); + emit itemSelected(items[activePosition()]); } void TabbedWidget::selectPreviousItem() { - if (current_position != 0) - current_position--; + if (activePosition() != 0) + active_position--; else - current_position = items.count() - 1; + active_position = items.count() - 1; refreshBuffer(); - emit itemSelected(items[current_position]); + emit itemSelected(items[activePosition()]); } +/* Disambiguate between affectPosition and activePosition */ void TabbedWidget::moveItemLeft() { - if (pressed_position != -1) + if (affectPosition() != -1) { - moveItemLeft(pressed_position); - pressed_position = -1; + moveItemLeft(affectPosition()); + resetAffectPosition(); + } + else { + moveItemLeft(activePosition()); } - else - moveItemLeft(current_position); } @@ -326,24 +333,25 @@ void TabbedWidget::moveItemLeft(int position) items[position] = neighbor_session_id; captions[position] = neighbor_caption; - if (position == current_position) - current_position--; - else if (position == current_position + 1) - current_position++; + if (position == activePosition()) + active_position--; + else if (position == activePosition() + 1) + active_position++; refreshBuffer(); } } +/* Disambiguate between affectPosition and activePosition */ void TabbedWidget::moveItemRight() { - if (pressed_position != -1) + if (affectPosition() != -1) { - moveItemRight(pressed_position); - pressed_position = -1; + moveItemRight(affectPosition()); + affect_position = -1; } else - moveItemRight(current_position); + moveItemRight(activePosition()); } void TabbedWidget::moveItemRight(int position) @@ -362,10 +370,10 @@ void TabbedWidget::moveItemRight(int position) items[position] = neighbor_session_id; captions[position] = neighbor_caption; - if (position == current_position) - current_position++; - else if (position == current_position - 1) - current_position--; + if (position == activePosition()) + active_position += 1; + else if (position == activePosition() - 1) + active_position -= 1; refreshBuffer(); } @@ -441,14 +449,14 @@ void TabbedWidget::mousePressEvent(QMouseEvent* e) for (position = 0, width = 0; (position < int(areas.count())) && (e->x() >= width); position++) width += areas[position]; - if ((e->x() <= width) && (e->button() == Qt::LeftButton) && !(current_position == position - 1)) + if ((e->x() <= width) && (e->button() == Qt::LeftButton) && !(activePosition() == position - 1)) { pressed = true; - pressed_position = position - 1; + affect_position = position - 1; } else if ((e->x() <= width) && (e->button() == Qt::RightButton)) { - pressed_position = position - 1; + affect_position = position - 1; if (!context_menu) createContextMenu(); @@ -479,15 +487,15 @@ void TabbedWidget::mouseReleaseEvent(QMouseEvent* e) for (position = 0, width = 0; (position < int(areas.count())) && (e->x() >= width); position++) width += areas[position]; - if ((e->x() <= width) && (e->button() == Qt::LeftButton) && !(current_position == position - 1)) + if ((e->x() <= width) && (e->button() == Qt::LeftButton) && !(activePosition() == position - 1)) { - if (pressed && pressed_position == (position - 1)) + if (pressed && affectPosition() == (position - 1)) { - current_position = position - 1; + active_position = position - 1; refreshBuffer(); - emit itemSelected(items[current_position]); + emit itemSelected(items[activePosition()]); } } @@ -509,7 +517,7 @@ void TabbedWidget::mouseDoubleClickEvent(QMouseEvent* e) for (position = 0, width = 0; (position < int(areas.count())) && (e->x() >= width); position++) width += areas[position]; - if ((e->x() <= width) && (e->button() == Qt::LeftButton) && current_position == position - 1) + if ((e->x() <= width) && (e->button() == Qt::LeftButton) && activePosition() == position - 1) { interactiveRename(position - 1); } @@ -566,12 +574,12 @@ const int TabbedWidget::drawButton(int position, QPainter& painter) // Initialize the painter. painter.setPen(font_color); - painter.setFont((position == current_position) ? selected_font : unselected_font); + painter.setFont((position == activePosition()) ? selected_font : unselected_font); // Draw the left border. - if (position == current_position) + if (position == activePosition()) tmp_pixmap = selected_left_image; - else if (position != current_position + 1) + else if (position != activePosition() + 1) tmp_pixmap = separator_image; painter.drawPixmap(x, 0, tmp_pixmap); @@ -584,7 +592,7 @@ const int TabbedWidget::drawButton(int position, QPainter& painter) width = metrics.width(captions[position]) + 10; - tmp_pixmap = (position == current_position) ? selected_image : unselected_image; + tmp_pixmap = (position == activePosition()) ? selected_image : unselected_image; painter.drawTiledPixmap(x, 0, width, height(), tmp_pixmap); painter.drawText(x, 0, width + 1, height() + 1, @@ -594,7 +602,7 @@ const int TabbedWidget::drawButton(int position, QPainter& painter) x += width; // Draw the right border if needed. - if (position == current_position) + if (position == activePosition()) { painter.drawPixmap(x, 0, selected_right_image); areas[position] += selected_right_image.width(); diff --git a/yakuake/src/tabbed_widget.h b/yakuake/src/tabbed_widget.h index f3a42b8..3e18302 100644 --- a/yakuake/src/tabbed_widget.h +++ b/yakuake/src/tabbed_widget.h @@ -41,8 +41,10 @@ class TabbedWidget : public TranslucentWidget explicit TabbedWidget(QWidget* parent = 0, const char* name = 0, bool translucency = false); ~TabbedWidget(); - int pressedPosition(); - void resetPressedPosition() { pressed_position = -1; } + int affectPosition(); + /* The operation is complete or cancelled; subsequent ops will use the + * active position. */ + void resetAffectPosition() { affect_position = -1; } void addItem(int session_id); int removeItem(int session_id); @@ -105,9 +107,19 @@ class TabbedWidget : public TranslucentWidget QString defaultTabCaption(int session_id); QString lowestAvailableCaption(); - int current_position; + int activePosition() const { + return active_position; + } + + /* Which tab is active now. */ + int active_position; + /* True if we recieved a click event *on* a tab. */ bool pressed; - int pressed_position; + /* Which position will be affected by changes. -1 if none. Eg, for + * a right-click context menu. */ + int affect_position; + /* Position we are editing the name of. Separate from affect_position + * because we can have a right click while we're editing. */ int edited_position; /* Tabs properties */ @@ -144,6 +156,9 @@ class TabbedWidget : public TranslucentWidget void slotRenameSelected(); void slotUpdateBuffer(const QPixmap& pixmap); void slotResetEditedPosition(); + /* Called after every new item selection to disregard the pointer set + * up by a previous right click. */ + void slotResetAffectPosition(); }; #endif /* TABBED_WIDGET_H */