Commit 1681d074 authored by Laurent Montel's avatar Laurent Montel 😁

Move tabwidget code in specific file

parent 111c0d8a
......@@ -21,6 +21,7 @@ set(blogilo_SRCS
blogsettings.cpp
uploadmediadialog.cpp
syncuploader.cpp
poststabwidget.cpp
composer/htmleditor.cpp
composer/stylegetter.cpp
composer/dialogs/addmediadialog.cpp
......
......@@ -359,7 +359,8 @@ void AddEditBlog::fetchedBlogId( const QList< QMap < QString , QString > > & lis
}
hideWaitWidget();
QString blogId, blogName, blogUrl, apiUrl;
if ( list.count() > 1 ) {
const int listCount(list.count());
if ( listCount > 1 ) {
kDebug() << "User has more than ONE blog!";
KDialog *blogsDialog = new KDialog(this);
QTableWidget *blogsList = new QTableWidget(blogsDialog);
......@@ -400,7 +401,7 @@ void AddEditBlog::fetchedBlogId( const QList< QMap < QString , QString > > & lis
return;
}
delete blogsDialog;
} else if (list.count() > 0) {
} else if (listCount > 0) {
blogId = list.constBegin()->value(QLatin1String("id"));
blogName = list.constBegin()->value(QLatin1String("title"));
blogUrl = list.constBegin()->value(QLatin1String("url"));
......@@ -456,7 +457,7 @@ void AddEditBlog::fetchedProfileId( const QString &id )
void AddEditBlog::enableOkButton( const QString & txt )
{
bool check = !txt.isEmpty();
const bool check = !txt.isEmpty();
enableButtonOk( check );
d->ui.txtTitle->setEnabled( check );
}
......
......@@ -59,7 +59,6 @@ int main( int argc, char *argv[] )
int r = app.exec();
global_end();
delete bilbo;
return r;
}
......@@ -33,6 +33,7 @@
#include "settings.h"
#include "bilboblog.h"
#include "blogsettings.h"
#include "poststabwidget.h"
#include "ui_advancedsettingsbase.h"
#include "ui_settingsbase.h"
......@@ -72,38 +73,11 @@ MainWindow::MainWindow()
kDebug();
setWindowTitle( i18n("Blogilo") );
tabPosts = new KTabWidget( this );
tabPosts->setElideMode( Qt::ElideRight );
tabPosts->setTabsClosable( true );
tabPosts->tabBar()->setSelectionBehaviorOnRemove( QTabBar::SelectPreviousTab );
tabPosts->setDocumentMode(true);
connect( tabPosts, SIGNAL(tabCloseRequested(int)), this, SLOT(slotRemovePostEntry(int)) );
tabPosts = new PostsTabWidget(this);
setCentralWidget( tabPosts );
mNewTabButton = new QToolButton( this );
mNewTabButton->setIcon( KIcon( QLatin1String( "tab-new" ) ) );
mNewTabButton->adjustSize();
mNewTabButton->setToolTip( i18nc("@info:tooltip", "Open a new tab"));
#ifndef QT_NO_ACCESSIBILITY
mNewTabButton->setAccessibleName( i18n( "New tab" ) );
#endif
tabPosts->setCornerWidget( mNewTabButton, Qt::TopLeftCorner );
connect( mNewTabButton, SIGNAL(clicked()),
SLOT(slotCreateNewPost()) );
mCloseTabButton = new QToolButton( this );
mCloseTabButton->setIcon( KIcon( QLatin1String( "tab-close" ) ) );
mCloseTabButton->adjustSize();
mCloseTabButton->setToolTip( i18nc("@info:tooltip", "Close the current tab"));
#ifndef QT_NO_ACCESSIBILITY
mCloseTabButton->setAccessibleName( i18n( "Close tab" ) );
#endif
tabPosts->setCornerWidget( mCloseTabButton, Qt::TopRightCorner );
connect( mCloseTabButton, SIGNAL(clicked()),
SLOT(slotCloseTabClicked()) );
connect(tabPosts,SIGNAL(createNewPost()),SLOT(slotCreateNewPost()));
connect(tabPosts,SIGNAL(closeTabClicked()),SLOT(slotCloseTabClicked()));
connect(tabPosts, SIGNAL(tabCloseRequested(int)), this, SLOT(slotRemovePostEntry(int)));
toolbox = new Toolbox( this );
......
......@@ -39,6 +39,7 @@ class QToolButton;
class Toolbox;
class KSelectAction;
class PostEntry;
class PostsTabWidget;
/**
Main window of blogilo...
......@@ -122,7 +123,7 @@ private:
QDockWidget *toolboxDock;
QPointer<PostEntry> activePost;
KStatusNotifierItem *systemTray;
KTabWidget *tabPosts;
PostsTabWidget *tabPosts;
int previousActivePostIndex;
......
/*
Copyright (c) 2013 Montel Laurent <montel.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "poststabwidget.h"
#include <KLocale>
#include <KIcon>
#include <KMenu>
#include <QToolButton>
#include <QTabBar>
PostsTabWidget::PostsTabWidget(QWidget *parent)
: KTabWidget(parent)
{
setElideMode( Qt::ElideRight );
setTabsClosable( true );
tabBar()->setSelectionBehaviorOnRemove( QTabBar::SelectPreviousTab );
setDocumentMode(true);
setMovable( true );
mNewTabButton = new QToolButton( this );
mNewTabButton->setIcon( KIcon( QLatin1String( "tab-new" ) ) );
mNewTabButton->adjustSize();
mNewTabButton->setToolTip( i18nc("@info:tooltip", "Open a new tab"));
#ifndef QT_NO_ACCESSIBILITY
mNewTabButton->setAccessibleName( i18n( "New tab" ) );
#endif
setCornerWidget( mNewTabButton, Qt::TopLeftCorner );
connect( mNewTabButton, SIGNAL(clicked()), this, SIGNAL(createNewPost()) );
mCloseTabButton = new QToolButton( this );
mCloseTabButton->setIcon( KIcon( QLatin1String( "tab-close" ) ) );
mCloseTabButton->adjustSize();
mCloseTabButton->setToolTip( i18nc("@info:tooltip", "Close the current tab"));
#ifndef QT_NO_ACCESSIBILITY
mCloseTabButton->setAccessibleName( i18n( "Close tab" ) );
#endif
setCornerWidget( mCloseTabButton, Qt::TopRightCorner );
connect( mCloseTabButton, SIGNAL(clicked()), this, SIGNAL(closeTabClicked()) );
setContextMenuPolicy( Qt::CustomContextMenu );
connect( this, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(slotTabContextMenuRequest(QPoint)) );
}
PostsTabWidget::~PostsTabWidget()
{
}
void PostsTabWidget::slotTabContextMenuRequest( const QPoint &pos )
{
QTabBar *bar = tabBar();
if ( count() < 1 ) return;
const int indexBar = bar->tabAt( bar->mapFrom( this, pos ) );
if ( indexBar == -1 )
return;
KMenu menu( this );
QAction *closeTab = menu.addAction( i18nc( "@action:inmenu", "Close Tab" ) );
closeTab->setIcon( KIcon( QLatin1String( "tab-close" ) ) );
QAction *allOther = menu.addAction( i18nc("@action:inmenu", "Close All Other Tabs" ) );
allOther->setEnabled( count() > 1 );
allOther->setIcon( KIcon( QLatin1String( "tab-close-other" ) ) );
QAction *action = menu.exec( mapToGlobal( pos ) );
if ( action == allOther ) { // Close all other tabs
/*
QList<Widget *> widgets;
const int index = q->indexOf( w );
for ( int i=0; i<q->count(); i++ ) {
if ( i==index) continue; // Skip the current one
Widget *other = qobject_cast<Widget *>( q->widget( i ) );
widgets << other;
}
foreach ( Widget *other, widgets ) {
delete other;
}
*/
} else if (action == closeTab) {
Q_EMIT tabCloseRequested(indexBar);
}
}
/*
Copyright (c) 2013 Montel Laurent <montel.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef POSTSTABWIDGET_H
#define POSTSTABWIDGET_H
#include <KTabWidget>
class QToolButton;
class PostsTabWidget : public KTabWidget
{
Q_OBJECT
public:
explicit PostsTabWidget(QWidget *parent);
~PostsTabWidget();
Q_SIGNALS:
void createNewPost();
void closeTabClicked();
private Q_SLOTS:
void slotTabContextMenuRequest(const QPoint&);
private:
QToolButton *mNewTabButton;
QToolButton *mCloseTabButton;
};
#endif // POSTSTABWIDGET_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment