Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow changing order of open document tabs #640

Merged
merged 4 commits into from
May 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/tiled/documentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

#include "abstracttool.h"
#include "maprenderer.h"
#include "movabletabwidget.h"

#include <QTabWidget>
#include <QUndoGroup>
#include <QFileInfo>

Expand All @@ -48,7 +48,7 @@ void DocumentManager::deleteInstance()

DocumentManager::DocumentManager(QObject *parent)
: QObject(parent)
, mTabWidget(new QTabWidget)
, mTabWidget(new MovableTabWidget)
, mUndoGroup(new QUndoGroup(this))
, mSelectedTool(0)
, mSceneWithTool(0)
Expand All @@ -60,6 +60,8 @@ DocumentManager::DocumentManager(QObject *parent)
SLOT(currentIndexChanged()));
connect(mTabWidget, SIGNAL(tabCloseRequested(int)),
SIGNAL(documentCloseRequested(int)));
connect(mTabWidget, SIGNAL(tabMoved(int,int)),
SLOT(documentTabMoved(int,int)));
}

DocumentManager::~DocumentManager()
Expand Down Expand Up @@ -253,6 +255,11 @@ void DocumentManager::updateDocumentTab()
mTabWidget->setTabToolTip(index, mapDocument->fileName());
}

void DocumentManager::documentTabMoved(int from, int to)
{
mDocuments.move(from, to);
}

void DocumentManager::centerViewOn(qreal x, qreal y)
{
MapView *view = currentMapView();
Expand Down
5 changes: 3 additions & 2 deletions src/tiled/documentmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <QList>
#include <QPair>

class QTabWidget;
class QUndoGroup;

namespace Tiled {
Expand All @@ -41,6 +40,7 @@ namespace Internal {
class MapDocument;
class MapScene;
class MapView;
class MovableTabWidget;

/**
* This class controls the open documents.
Expand Down Expand Up @@ -159,14 +159,15 @@ public slots:
private slots:
void currentIndexChanged();
void updateDocumentTab();
void documentTabMoved(int from, int to);

private:
DocumentManager(QObject *parent = 0);
~DocumentManager();

QList<MapDocument*> mDocuments;

QTabWidget *mTabWidget;
MovableTabWidget *mTabWidget;
QUndoGroup *mUndoGroup;
AbstractTool *mSelectedTool;
MapScene *mSceneWithTool;
Expand Down
34 changes: 34 additions & 0 deletions src/tiled/movabletabwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* movabletabwidget.cpp
* Copyright 2010, Stefan Beller <stefanbeller@googlemail.com>
* Copyright 2010, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
*
* This file is part of Tiled.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "movabletabwidget.h"

#include <QTabBar>

using namespace Tiled;
using namespace Tiled::Internal;

MovableTabWidget::MovableTabWidget()
{
setMovable(true);
connect(tabBar(), SIGNAL(tabMoved(int,int)),
SIGNAL(tabMoved(int,int)));
}
55 changes: 55 additions & 0 deletions src/tiled/movabletabwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* movabletabwidget.h
* Copyright 2010, Stefan Beller <stefanbeller@googlemail.com>
* Copyright 2010, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
*
* This file is part of Tiled.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MOVABLE_TAB_WIDGET_H
#define MOVABLE_TAB_WIDGET_H

#include <QTabWidget>

namespace Tiled {
namespace Internal {

/**
* A QTabWidget that has movable tabs by default and forwards its QTabBar's
* tabMoved signal.
*/
class MovableTabWidget : public QTabWidget
{
Q_OBJECT

public:
/**
* Constructor
*/
MovableTabWidget();

signals:
/**
* Emitted when a tab is moved from index position \a from to
* index position \a to.
*/
void tabMoved(int from, int to);
};

} // namespace Tiled::Internal
} // namespace Tiled

#endif // MOVABLE_TAB_WIDGET_H
2 changes: 2 additions & 0 deletions src/tiled/tiled.pro
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ SOURCES += aboutdialog.cpp \
mapview.cpp \
minimap.cpp \
minimapdock.cpp \
movabletabwidget.cpp \
movelayer.cpp \
movemapobject.cpp \
movemapobjecttogroup.cpp \
Expand Down Expand Up @@ -220,6 +221,7 @@ HEADERS += aboutdialog.h \
mapview.h \
minimap.h \
minimapdock.h \
movabletabwidget.h \
movelayer.h \
movemapobject.h \
movemapobjecttogroup.h \
Expand Down