Add menu items to rearrange taskbar entries

Make taskbar drag and drop moving more robust
This resolves Bug 1103
pull/2/head
Timothy Pearson 11 years ago
parent a733ce41cb
commit 3df12cd876

@ -172,6 +172,7 @@ TaskbarConfig::TaskbarConfig(TQWidget *parent, const char* name, const TQStringL
connect(m_widget->globalConfigReload, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotReloadConfigurationFromGlobals()));
connect(m_widget->globalConfigEdit, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotEditGlobalConfiguration()));
connect(m_widget->kcfg_UseGlobalSettings, TQT_SIGNAL(clicked()), this, TQT_SLOT(processLockouts()));
connect(m_widget->kcfg_SortByApp, TQT_SIGNAL(clicked()), this, TQT_SLOT(processLockouts()));
TQFile configFile(locateLocal("config", m_configFileName));
if (!configFile.exists())
@ -298,6 +299,8 @@ void TaskbarConfig::processLockouts()
m_widget->globalConfigEdit->hide();
}
}
m_widget->kcfg_AllowDragAndDropReArrange->setEnabled(!m_widget->kcfg_SortByApp->isChecked());
}
void TaskbarConfig::slotReloadConfigurationFromGlobals()

@ -70,7 +70,7 @@
<cstring>globalConfigReload</cstring>
</property>
<property name="text">
<string>Overwrite current configuration with the current global taskbar configuration</string>
<string>Overwrite current configuration with the current global floating taskbar configuration</string>
</property>
</widget>
<widget class="TQPushButton" row="3" column="0" rowspan="1" colspan="2">
@ -78,7 +78,7 @@
<cstring>globalConfigEdit</cstring>
</property>
<property name="text">
<string>Edit global taskbar configuration</string>
<string>Edt global floating taskbar configuration</string>
</property>
</widget>
</grid>
@ -130,7 +130,7 @@ By default this option is selected.</string>
By default, this option is selected and all windows are shown.</string>
</property>
</widget>
<widget class="TQCheckBox" row="8" column="0" rowspan="1" colspan="3">
<widget class="TQCheckBox" row="4" column="1" rowspan="1" colspan="2">
<property name="name">
<cstring>kcfg_AllowDragAndDropReArrange</cstring>
</property>
@ -144,7 +144,7 @@ By default, this option is selected and all windows are shown.</string>
<string>Turning this option on will allow tasks on the taskbar to be manually rearranged using drag and drop.</string>
</property>
</widget>
<widget class="TQCheckBox" row="7" column="0" rowspan="1" colspan="3">
<widget class="TQCheckBox" row="8" column="0" rowspan="1" colspan="3">
<property name="name">
<cstring>kcfg_ShowWindowListBtn</cstring>
</property>
@ -216,7 +216,7 @@ By default the taskbar groups windows when it is full.</string>
<cstring>kcfg_ShowTaskStates</cstring>
</property>
</widget>
<widget class="TQCheckBox" row="5" column="0" rowspan="1" colspan="3">
<widget class="TQCheckBox" row="6" column="0" rowspan="1" colspan="3">
<property name="name">
<cstring>kcfg_ShowOnlyIconified</cstring>
</property>
@ -229,7 +229,7 @@ By default the taskbar groups windows when it is full.</string>
By default, this option is not selected and the taskbar will show all windows.</string>
</property>
</widget>
<widget class="TQCheckBox" row="6" column="0" rowspan="1" colspan="3">
<widget class="TQCheckBox" row="7" column="0" rowspan="1" colspan="3">
<property name="name">
<cstring>kcfg_ShowIcon</cstring>
</property>
@ -437,7 +437,7 @@ By default, this option is selected and all windows are shown.</string>
<bool>true</bool>
</property>
</widget>
<widget class="TQCheckBox" row="4" column="0" rowspan="1" colspan="3">
<widget class="TQCheckBox" row="5" column="0" rowspan="1" colspan="3">
<property name="name">
<cstring>kcfg_CycleWheel</cstring>
</property>

@ -1295,7 +1295,46 @@ void TaskBar::sortContainersByDesktop(TaskContainer::List& list)
}
}
int TaskBar::taskMoveHandler(const TQPoint &pos, Task::List taskList) {
TaskMoveDestination::TaskMoveDestination TaskBar::taskMoveCapabilities(TaskContainer* movingContainer) {
TaskMoveDestination::TaskMoveDestination ret = TaskMoveDestination::Null;
bool before = false;
bool after = false;
bool movingFound = false;
if (movingContainer) {
// Check to see if there are any visible containers before or after the movingContainer
TaskContainer::Iterator it = containers.begin();
for (; it != containers.end(); ++it)
{
TaskContainer* c = *it;
if (!c->isVisibleTo(this)) {
continue;
}
if (c == movingContainer) {
movingFound = true;
}
else {
if (movingFound) {
after = true;
}
else {
before = true;
}
}
}
if (before) {
ret = ret | TaskMoveDestination::Left;
}
if (after) {
ret = ret | TaskMoveDestination::Right;
}
}
return ret;
}
int TaskBar::taskMoveHandler(TaskMoveDestination::TaskMoveDestination dest, Task::List taskList, const TQPoint pos) {
TaskContainer* movingContainer = NULL;
TaskContainer* destContainer = NULL;
bool movingRight = true;
@ -1304,6 +1343,9 @@ int TaskBar::taskMoveHandler(const TQPoint &pos, Task::List taskList) {
for (; it != containers.end(); ++it)
{
TaskContainer* c = *it;
if (!c->isVisibleTo(this)) {
continue;
}
if (c->taskList() == taskList) {
movingContainer = c;
break;
@ -1311,11 +1353,15 @@ int TaskBar::taskMoveHandler(const TQPoint &pos, Task::List taskList) {
}
if (movingContainer) {
if (dest == TaskMoveDestination::Position) {
// Find the best place for the container to go...
it = containers.begin();
for (; it != containers.end(); ++it)
{
TaskContainer* c = *it;
if (!c->isVisibleTo(this)) {
continue;
}
TQPoint containerPos = c->pos();
TQSize containerSize = c->size();
TQRect containerRect(containerPos.x(), containerPos.y(), containerSize.width(), containerSize.height());
@ -1331,6 +1377,74 @@ int TaskBar::taskMoveHandler(const TQPoint &pos, Task::List taskList) {
break;
}
}
}
else if (dest == TaskMoveDestination::Beginning) {
// Move to beginning
it = containers.begin();
while ((it != containers.end()) && (!(*it)->isVisibleTo(this))) {
it++;
}
if (it == containers.end()) {
return false;
}
destContainer = *it;
movingRight = false;
}
else if (dest == TaskMoveDestination::Left) {
// Move left
it = containers.begin();
while ((it != containers.end()) && (!(*it)->isVisibleTo(this))) {
it++;
}
if (it == containers.end()) {
return false;
}
TaskContainer* prev = *it;
destContainer = prev;
for (; it != containers.end(); ++it)
{
TaskContainer* c = *it;
if (!c->isVisibleTo(this)) {
continue;
}
if (movingContainer == c) {
destContainer = prev;
break;
}
prev = c;
}
movingRight = false;
}
else if (dest == TaskMoveDestination::Right) {
// Move right
it = containers.begin();
destContainer = NULL;
for (; it != containers.end(); ++it)
{
TaskContainer* c = *it;
if (!c->isVisibleTo(this)) {
continue;
}
if (movingContainer == c) {
if (it != containers.end()) {
it++;
while ((it != containers.end()) && (!(*it)->isVisibleTo(this))) {
it++;
}
}
if ((it != containers.end()) && ((*it)->isVisibleTo(this))) {
destContainer = *it;
}
break;
}
}
movingRight = true;
}
else if (dest == TaskMoveDestination::End) {
// Move to end
destContainer = NULL;
movingRight = true;
}
if (destContainer == movingContainer) {
return false;
@ -1343,8 +1457,11 @@ int TaskBar::taskMoveHandler(const TQPoint &pos, Task::List taskList) {
it = containers.find(destContainer);
if ((it != containers.end()) && (movingRight)) {
it++;
while ((it != containers.end()) && (!(*it)->isVisibleTo(this))) {
it++;
}
if (it != containers.end()) {
}
if ((it != containers.end()) && ((*it)->isVisibleTo(this))) {
containers.insert(it, movingContainer);
}
else {

@ -39,6 +39,34 @@ class Startup;
class Task;
class TDEGlobalAccel;
namespace TaskMoveDestination
{
enum TaskMoveDestination
{
Null = 0x00,
Position = 0x01,
Left = 0x02,
Right = 0x04,
Beginning = 0x08,
End = 0x10
};
inline TaskMoveDestination operator|(TaskMoveDestination a, TaskMoveDestination b)
{
return static_cast<TaskMoveDestination>(static_cast<int>(a) | static_cast<int>(b));
}
inline TaskMoveDestination operator&(TaskMoveDestination a, TaskMoveDestination b)
{
return static_cast<TaskMoveDestination>(static_cast<int>(a) & static_cast<int>(b));
}
inline TaskMoveDestination operator~(TaskMoveDestination a)
{
return static_cast<TaskMoveDestination>(~static_cast<int>(a));
}
};
class TaskBar : public Panner
{
Q_OBJECT
@ -65,7 +93,8 @@ public:
KTextShadowEngine *textShadowEngine();
int taskMoveHandler(const TQPoint &pos, Task::List taskList);
int taskMoveHandler(TaskMoveDestination::TaskMoveDestination dest, Task::List taskList, const TQPoint pos = TQPoint(0,0));
TaskMoveDestination::TaskMoveDestination taskMoveCapabilities(TaskContainer* movingContainer);
public slots:
void configure();

@ -338,12 +338,10 @@ void TaskBarContainer::dragEnterEvent( TQDragEnterEvent* e )
return;
}
if (TaskDrag::canDecode(e) && READ_MERGED_TASBKAR_SETTING(allowDragAndDropReArrange))
if ((e->source()->parent() == taskBar->viewport()) && TaskDrag::canDecode(e) && READ_MERGED_TASBKAR_SETTING(allowDragAndDropReArrange) && (!READ_MERGED_TASBKAR_SETTING(sortByApp)))
{
if (!READ_MERGED_TASBKAR_SETTING(sortByApp)) {
e->accept();
}
}
}
void TaskBarContainer::dragLeaveEvent( TQDragLeaveEvent* e )
@ -359,12 +357,10 @@ void TaskBarContainer::dropEvent( TQDropEvent* e )
return;
}
if (TaskDrag::canDecode(e) && READ_MERGED_TASBKAR_SETTING(allowDragAndDropReArrange))
if ((e->source()->parent() == taskBar->viewport()) && TaskDrag::canDecode(e) && READ_MERGED_TASBKAR_SETTING(allowDragAndDropReArrange) && (!READ_MERGED_TASBKAR_SETTING(sortByApp)))
{
if (!READ_MERGED_TASBKAR_SETTING(sortByApp)) {
if (taskBar->taskMoveHandler(taskBar->mapFrom(this, e->pos()), TaskDrag::decode(e))) {
if (taskBar->taskMoveHandler(TaskMoveDestination::Position, TaskDrag::decode(e), taskBar->mapFrom(this, e->pos()))) {
e->accept();
}
}
}
}

@ -1224,7 +1224,7 @@ void TaskContainer::popupMenu(int action)
return;
}
m_menu = new TaskRMBMenu(m_filteredTasks, taskBar->showAllWindows());
m_menu = new TaskRMBMenu(m_filteredTasks, taskBar->showAllWindows(), (READ_MERGED_TASBKAR_SETTING(allowDragAndDropReArrange))?makeTaskMoveMenu():NULL);
}
else
{
@ -1262,6 +1262,58 @@ void TaskContainer::popupMenu(int action)
m_menu = 0;
}
TQPopupMenu* TaskContainer::makeTaskMoveMenu()
{
TaskMoveDestination::TaskMoveDestination capabilities = taskBar->taskMoveCapabilities(this);
int id;
TQPopupMenu* menu = new TQPopupMenu();
menu->setCheckable(false);
id = menu->insertItem(SmallIconSet("start"),
i18n("Move to Beginning"),
this, TQT_SLOT(slotTaskMoveBeginning()));
menu->setItemEnabled(id, (capabilities & TaskMoveDestination::Left));
id = menu->insertItem(SmallIconSet("back"),
i18n("Move Left"),
this, TQT_SLOT(slotTaskMoveLeft()));
menu->setItemEnabled(id, (capabilities & TaskMoveDestination::Left));
id = menu->insertItem(SmallIconSet("forward"),
i18n("Move Right"),
this, TQT_SLOT(slotTaskMoveRight()));
menu->setItemEnabled(id, (capabilities & TaskMoveDestination::Right));
id = menu->insertItem(SmallIconSet("finish"),
i18n("Move to End"),
this, TQT_SLOT(slotTaskMoveEnd()));
menu->setItemEnabled(id, (capabilities & TaskMoveDestination::Right));
return menu;
}
void TaskContainer::slotTaskMoveBeginning()
{
taskBar->taskMoveHandler(TaskMoveDestination::Beginning, taskList());
}
void TaskContainer::slotTaskMoveLeft()
{
taskBar->taskMoveHandler(TaskMoveDestination::Left, taskList());
}
void TaskContainer::slotTaskMoveRight()
{
taskBar->taskMoveHandler(TaskMoveDestination::Right, taskList());
}
void TaskContainer::slotTaskMoveEnd()
{
taskBar->taskMoveHandler(TaskMoveDestination::End, taskList());
}
void TaskContainer::mouseMoveEvent( TQMouseEvent* e )
{
kdDebug() << "regular move" << endl;
@ -1399,12 +1451,10 @@ void TaskContainer::dragEnterEvent( TQDragEnterEvent* e )
return;
}
if (TaskDrag::canDecode(e) && READ_MERGED_TASBKAR_SETTING(allowDragAndDropReArrange))
if ((e->source()->parent() == this->parent()) && TaskDrag::canDecode(e) && READ_MERGED_TASBKAR_SETTING(allowDragAndDropReArrange) && (!READ_MERGED_TASBKAR_SETTING(sortByApp)))
{
if (!READ_MERGED_TASBKAR_SETTING(sortByApp)) {
e->accept();
}
}
// if a dragitem is held for over a taskbutton for two seconds,
// activate corresponding window
@ -1429,14 +1479,12 @@ void TaskContainer::dropEvent( TQDropEvent* e )
return;
}
if (TaskDrag::canDecode(e) && READ_MERGED_TASBKAR_SETTING(allowDragAndDropReArrange))
if ((e->source()->parent() == this->parent()) && TaskDrag::canDecode(e) && READ_MERGED_TASBKAR_SETTING(allowDragAndDropReArrange) && (!READ_MERGED_TASBKAR_SETTING(sortByApp)))
{
if (!READ_MERGED_TASBKAR_SETTING(sortByApp)) {
if (taskBar->taskMoveHandler(TQWidget::mapTo(taskBar, e->pos()), TaskDrag::decode(e))) {
if (taskBar->taskMoveHandler(TaskMoveDestination::Position, TaskDrag::decode(e), TQWidget::mapTo(taskBar, e->pos()))) {
e->accept();
}
}
}
dragSwitchTimer.stop();

@ -127,8 +127,14 @@ protected slots:
void taskChanged(bool geometryChangeOnly);
void showMe();
void slotTaskMoveBeginning();
void slotTaskMoveLeft();
void slotTaskMoveRight();
void slotTaskMoveEnd();
private:
void checkAttention(const Task::Ptr changed_task = NULL);
TQPopupMenu* makeTaskMoveMenu();
TQString sid;
TQTimer animationTimer;
TQTimer dragSwitchTimer;

@ -38,10 +38,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "taskrmbmenu.h"
#include "taskrmbmenu.moc"
TaskRMBMenu::TaskRMBMenu(const Task::List& theTasks, bool show, TQWidget *parent, const char *name)
TaskRMBMenu::TaskRMBMenu(const Task::List& theTasks, bool show, TQPopupMenu* moveMenu, TQWidget *parent, const char *name)
: TQPopupMenu( parent, name )
, tasks( theTasks )
, showAll( show )
, taskMoveMenu( moveMenu )
{
assert(tasks.count() > 0);
if (tasks.count() == 1)
@ -57,6 +58,7 @@ TaskRMBMenu::TaskRMBMenu(const Task::List& theTasks, bool show, TQWidget *parent
TaskRMBMenu::TaskRMBMenu(Task::Ptr task, bool show, TQWidget *parent, const char *name)
: TQPopupMenu( parent, name )
, showAll( show )
, taskMoveMenu( NULL )
{
fillMenu(task);
}
@ -106,6 +108,13 @@ void TaskRMBMenu::fillMenu(Task::Ptr t)
insertSeparator();
if (taskMoveMenu) {
taskMoveMenu->reparent(this, taskMoveMenu->getWFlags(), taskMoveMenu->geometry().topLeft(), FALSE);
insertItem(i18n("Move Task Button"), taskMoveMenu);
insertSeparator();
}
id = insertItem(SmallIcon("fileclose"), i18n("&Close"), t, TQT_SLOT(close()));
setItemEnabled(id, !checkActions || t->info().actionSupported(NET::ActionClose));
}

@ -32,7 +32,7 @@ class KDE_EXPORT TaskRMBMenu : public TQPopupMenu
Q_OBJECT
public:
TaskRMBMenu(const Task::List&, bool showAll = true, TQWidget *parent = 0, const char *name = 0);
TaskRMBMenu(const Task::List&, bool showAll = true, TQPopupMenu* moveMenu = NULL, TQWidget *parent = 0, const char *name = 0);
TaskRMBMenu(Task::Ptr, bool showAll = true, TQWidget *parent = 0, const char *name = 0);
private:
@ -54,6 +54,7 @@ private slots:
private:
Task::List tasks;
bool showAll;
TQPopupMenu* taskMoveMenu;
};
#endif

Loading…
Cancel
Save