OSDN Git Service

refactoring.
[kita/kita.git] / kita / src / kitaui / tabwidgetbase.cpp
index bd44c14..c436260 100644 (file)
@@ -41,7 +41,7 @@
 
 
 KitaTabWidgetBase::KitaTabWidgetBase( QWidget* parent, const char* name, WFlags f )
-        : QTabWidget( parent, name, f )
+        : KTabWidget( parent, name, f )
 {
     connectSignals();
     setupActions();
@@ -75,57 +75,6 @@ KitaTabWidgetBase::~KitaTabWidgetBase()
     }
 }
 
-
-/* public */ /* virtual */
-void KitaTabWidgetBase::addTab( QWidget* w, const QString& label )
-{
-    KitaTabBase * tb = new KitaTabBase( label );  /* KitaTabBase is deleted automatically. */
-    static_cast< KitaTabBarBase* >( tabBar() ) ->adjustTabWidth( tb );
-    QTabWidget::addTab( w, tb );
-}
-
-
-/* public */ /* virtual */
-void KitaTabWidgetBase::addTab( QWidget* w, const QIconSet & iconset, const QString& label )
-{
-    KitaTabBase * tb = new KitaTabBase( label );  /* KitaTabBase is deleted automatically. */
-    tb->setIconSet( iconset );
-    static_cast< KitaTabBarBase* >( tabBar() ) ->adjustTabWidth( tb );
-    QTabWidget::addTab( w, tb );
-}
-
-
-/* public */ /* virtual */
-void KitaTabWidgetBase::insertTab( QWidget* w, const QString& label, int index )
-{
-    KitaTabBase * tb = new KitaTabBase( label );  /* KitaTabBase is deleted automatically. */
-    static_cast< KitaTabBarBase* >( tabBar() ) ->adjustTabWidth( tb );
-    QTabWidget::insertTab( w, tb, index );
-}
-
-
-/* public */ /* virtual */
-void KitaTabWidgetBase::removePage( QWidget* w )
-{
-    QTabWidget::removePage( w );
-    static_cast< KitaTabBarBase* >( tabBar() ) ->adjustTabWidth( NULL );
-}
-
-
-/* public */ /* virtual */
-void KitaTabWidgetBase::setTabLabel( QWidget * w, const QString & label )
-{
-    int idx = indexOf( w );
-    KitaTabBase* ktb = static_cast < KitaTabBase* >( tabBar() ->tabAt( idx ) );
-
-    if ( ktb->getFullText() != label ) {
-        ktb->setFullText( label );
-        QTabWidget::setTabLabel( w, label );
-        static_cast< KitaTabBarBase* >( tabBar() ) ->adjustTabWidth( NULL );
-    }
-}
-
-
 /* public slot  */
 void KitaTabWidgetBase::slotCurrentChanged( QWidget * w )
 {
@@ -228,42 +177,11 @@ void KitaTabWidgetBase::connectSignals()
     /* connect signals */
     Kita::SignalCollection * signalCollection = Kita::SignalCollection::getInstance();
 
-    connect( this, SIGNAL( switchToBoard() ),
-             signalCollection, SIGNAL( switchToBoard() ) );
-
-    connect( this, SIGNAL( switchToSubject() ),
-             signalCollection, SIGNAL( switchToSubject() ) );
-
-    connect( this, SIGNAL( switchToThread() ),
-             signalCollection, SIGNAL( switchToThread() ) );
-
-    connect( this, SIGNAL( switchToKitanavi() ),
-             signalCollection, SIGNAL( switchToKitanavi() ) );
-
-    connect( this, SIGNAL( switchToImgview() ),
-             signalCollection, SIGNAL( switchToImgview() ) );
-
-    connect( this, SIGNAL( switchToWritedock() ),
-             signalCollection, SIGNAL( switchToWritedock() ) );
-
     connect( this, SIGNAL( currentChanged ( QWidget * ) ),
              SLOT( slotCurrentChanged ( QWidget * ) ) );
 
-    connect( this, SIGNAL( setMainStatusbar( const QString& ) ),
-             signalCollection, SIGNAL( setMainStatusbar ( const QString& ) ) );
-
-    connect( this, SIGNAL( setMainURLLine( const KURL& ) ),
-             signalCollection, SIGNAL( setMainURLLine( const KURL& ) ) );
-
-    connect( this, SIGNAL( setMainCaption( const QString& ) ),
-             signalCollection, SIGNAL( setMainCaption( const QString& ) ) );
-
-    connect( this, SIGNAL( openURLRequestExt(
-                               const KURL&, const KParts::URLArgs&, QString, int,
-                               const KURL& ) ),
-             signalCollection, SIGNAL( openURLRequestExt(
-                                           const KURL& , const KParts::URLArgs&, QString, int,
-                                           const KURL& ) ) );
+    connect( this, SIGNAL( openURLRequestExt( const KURL&, const QString ) ),
+             signalCollection, SIGNAL( openURLRequestExt( const KURL&, const QString ) ) );
 }
 
 
@@ -286,22 +204,14 @@ void KitaTabWidgetBase::setupActions()
                  "tab_configkeys" );
 
     new KAction( i18n( "Activate Next Tab" ),
-#if KDE_IS_VERSION( 3, 2, 0 )
                  KStdAccel::tabNext(),
-#else
-                 KShortcut( Qt::CTRL + Qt::Key_Period ),
-#endif
                  this,
                  SLOT( slotNextTab() ),
                  actionCollection(),
                  "tab_nexttab" );
 
     new KAction( i18n( "Activate Previous Tab" ),
-#if KDE_IS_VERSION( 3, 2, 0 )
                  KStdAccel::tabPrev(),
-#else
-                 KShortcut( Qt::CTRL + Qt::Key_Comma ),
-#endif
                  this,
                  SLOT( slotPrevTab() ),
                  actionCollection(),
@@ -341,48 +251,6 @@ void KitaTabWidgetBase::setupActions()
                  SLOT( slotCloseAllTab() ),
                  actionCollection(),
                  "tab_closealltab" );
-
-    new KAction( i18n( "Switch to Board" ),
-                 Key_1,
-                 this,
-                 SIGNAL( switchToBoard() ),
-                 actionCollection(),
-                 "tab_toboard" );
-
-    new KAction( i18n( "Switch to Subject" ),
-                 Key_2,
-                 this,
-                 SIGNAL( switchToSubject() ),
-                 actionCollection(),
-                 "tab_tosubject" );
-
-    new KAction( i18n( "Switch to Thread" ),
-                 Key_3,
-                 this,
-                 SIGNAL( switchToThread() ),
-                 actionCollection(),
-                 "tab_tothread" );
-
-    new KAction( i18n( "Switch to KitaNavi" ),
-                 Key_4,
-                 this,
-                 SIGNAL( switchToKitanavi() ),
-                 actionCollection(),
-                 "tab_tokitanavi" );
-
-    new KAction( i18n( "Switch to Imgviewer" ),
-                 Key_5,
-                 this,
-                 SIGNAL( switchToImgview() ),
-                 actionCollection(),
-                 "tab_toimgview" );
-
-    new KAction( i18n( "Switch to writedock" ),
-                 Key_6,
-                 this,
-                 SIGNAL( switchToWritedock() ),
-                 actionCollection(),
-                 "tab_towritedock" );
 }
 
 
@@ -507,293 +375,12 @@ void KitaTabWidgetBase::slotCloseAllTab()
 
 
 
-KitaTabBarBase::KitaTabBarBase( QWidget* parent, const char* name ) : QTabBar( parent, name ) {}
-
-KitaTabBarBase::~KitaTabBarBase() {}
-
-
-/* protected */ /* virtual */
-void KitaTabBarBase::mousePressEvent( QMouseEvent *e )
-{
-    if ( e->button() == RightButton ) {
-        QTab * tab = selectTab( e->pos() );
-        if ( tab != NULL ) {
-            int idx = indexOf( tab->identifier() );
-            showPopupMenu( idx, mapToGlobal( e->pos() ) );
-            return ;
-        }
-    }
-    QTabBar::mousePressEvent( e );
-}
-
-
-
-/* private */ /* virtual */
-void KitaTabBarBase::showPopupMenu( int idx, QPoint global )
-{
-    enum{
-        MENU_CLOSE,
-        MENU_CLOSEOTHER,
-        MENU_CLOSELEFT,
-        MENU_CLOSERIGHT
-    };
-
-    KitaTabWidgetBase* tabwidget = static_cast<KitaTabWidgetBase*>( parentWidget() );
-    KActionCollection * collection = tabwidget->actionCollection();
-
-    KPopupMenu* popup = new KPopupMenu( this );
-    popup->clear();
-
-    popup->insertItem( i18n( "Close this tab" ) , MENU_CLOSE );
-    collection->action( "tab_prevtab" ) ->plug( popup );
-    collection->action( "tab_nexttab" ) ->plug( popup );
-    popup->insertSeparator();
-
-    popup->insertItem( i18n( "Close Other Tabs" ) , MENU_CLOSEOTHER );
-    popup->insertItem( i18n( "Close right tabs" ) , MENU_CLOSERIGHT );
-    popup->insertItem( i18n( "Close left tabs" ) , MENU_CLOSELEFT );
-    collection->action( "tab_closealltab" ) ->plug( popup );
-
-    popup->insertSeparator();
-    collection->action( "tab_configkeys" ) ->plug( popup );
-
-    int ret = popup->exec( global );
-    delete popup;
-
-    switch ( ret ) {
-    case MENU_CLOSE: tabwidget->slotCloseTab( idx ); break;
-    case MENU_CLOSEOTHER: tabwidget->slotCloseOtherTab( idx ); break;
-    case MENU_CLOSERIGHT: tabwidget->slotCloseRightTab( idx ); break;
-    case MENU_CLOSELEFT: tabwidget->slotCloseLeftTab( idx ); break;
-    }
-
-}
-
-
-/* public */
-void KitaTabBarBase::adjustTabWidth( KitaTabBase* newTab )
-{
-    if ( count() == 0 ) return ;
-    if ( tabAt( 0 ) ->text().length() == 0 ) return ; /* maybe this is image tab */
-
-    if ( !shrinkTab( newTab ) ) expandTab();
-}
-
-
-/* private */
-bool KitaTabBarBase::shrinkTab( KitaTabBase* newTab )
-{
-    const int minwidth = 240;
-    const int mrg = 32;
-
-    int beforewd = 0;
-    int afterwd = 0;
-    bool chgWidth = FALSE;
-    int tabnum = count();
-    if ( newTab ) ++tabnum;
-    unsigned int* lng = new unsigned int[ tabnum ];
-    int* tabwd = new int[ tabnum ];
-    KitaTabBase** ktb = new KitaTabBase * [ tabnum ];
-    int parentWidth = QMAX( minwidth, parentWidget() ->width() - mrg );
-    QFontMetrics fm( parentWidget() ->font() );
-    int tabmrg = tabAt( 0 ) ->rect().width() - fm.width( tabAt( 0 ) ->text() );
-
-    for ( int i = 0; i < count(); ++i ) ktb[ i ] = static_cast< KitaTabBase* >( tabAt( i ) );
-    if ( newTab ) ktb[ tabnum - 1 ] = newTab;
-
-    /* get the current width */
-    for ( int i = 0; i < tabnum; ++i ) {
-        lng[ i ] = ktb[ i ] ->text().length();
-        if ( lng[ i ] != ktb[ i ] ->getTextLng() ) lng[ i ] -= 2; /* remove the length of ".." */
-        tabwd[ i ] = fm.width( ktb[ i ] ->text() );
-        beforewd += ( tabwd[ i ] + tabmrg );
-    }
-    if ( beforewd <= parentWidth + mrg / 2 ) return FALSE;
-
-    afterwd = beforewd;
-    for ( ;; ) {
-
-        int maxwd;
-        int idx;
-
-        /* find the tab which has the largest width. */
-        maxwd = 0;
-        idx = -1;
-        for ( int i = 0; i < tabnum; ++i ) {
-            if ( lng[ i ] > 2 && tabwd[ i ] > maxwd ) {
-                maxwd = tabwd[ i ];
-                idx = i;
-            }
-        }
-        if ( idx == -1 ) break;
-
-        chgWidth = TRUE;
-        if ( lng[ idx ] == ktb[ idx ] ->getTextLng() ) lng[ idx ] = ktb[ idx ] ->getTextLng() - 3;
-        else --lng[ idx ];
-        afterwd -= tabwd[ idx ];
-        QString text = ktb[ idx ] ->getFullText().left( lng[ idx ] ) + "..";
-        tabwd[ idx ] = fm.width( text );
-        afterwd += tabwd[ idx ];
-
-        if ( afterwd <= parentWidth ) break;
-    }
-
-    /* set new texts */
-    if ( beforewd != afterwd && chgWidth ) {
-
-        for ( int i = 0; i < tabnum; ++i ) {
-
-            if ( lng[ i ] != ktb[ i ] ->text().length() ) {
-
-                QString text = ktb[ i ] ->getFullText().left( lng[ i ] ) + "..";
-                ktb[ i ] ->setText( text );
-            }
-        }
-    }
-
-    delete lng;
-    delete ktb;
-    delete tabwd;
-    return chgWidth;
-}
-
-
-
-
-/* private */
-bool KitaTabBarBase::expandTab()
-{
-    const int minwidth = 240;
-    const int mrg = 32;
-
-    int beforewd = 0;
-    int afterwd = 0;
-    bool chgWidth = FALSE;
-    int tabnum = count();
-    unsigned int* lng = new unsigned int[ tabnum ];
-    int* tabwd = new int[ tabnum ];
-    KitaTabBase** ktb = new KitaTabBase * [ tabnum ];
-    int parentWidth = QMAX( minwidth, parentWidget() ->width() - mrg );
-    QFontMetrics fm( parentWidget() ->font() );
-    int tabmrg = tabAt( 0 ) ->rect().width() - fm.width( tabAt( 0 ) ->text() );
-
-    for ( int i = 0; i < count(); ++i ) ktb[ i ] = static_cast< KitaTabBase* >( tabAt( i ) );
-
-    /* get the current width */
-    for ( int i = 0; i < tabnum; ++i ) {
-        lng[ i ] = ktb[ i ] ->text().length();
-        if ( lng[ i ] != ktb[ i ] ->getTextLng() ) lng[ i ] -= 2; /* remove the length of ".." */
-        tabwd[ i ] = fm.width( ktb[ i ] ->text() );
-        beforewd += ( tabwd[ i ] + tabmrg );
-    }
-    if ( parentWidth - mrg / 2 <= beforewd ) return FALSE;
-
-    afterwd = beforewd;
-    for ( ;; ) {
-
-        int minwd;
-        int idx;
-
-        /* find the tab which has the smallest width. */
-        minwd = parentWidth;
-        idx = -1;
-        for ( int i = 0; i < tabnum; ++i ) {
-            if ( lng[ i ] != ktb[ i ] ->getTextLng() && tabwd[ i ] < minwd ) {
-                minwd = tabwd[ i ];
-                idx = i;
-            }
-        }
-        if ( idx == -1 ) break;
-
-        chgWidth = TRUE;
-        if ( lng[ idx ] >= ktb[ idx ] ->getTextLng() - 3 ) lng[ idx ] = ktb[ idx ] ->getTextLng();
-        else ++lng[ idx ];
-        afterwd -= tabwd[ idx ];
-        QString text = ktb[ idx ] ->getFullText().left( lng[ idx ] );
-        if ( lng[ idx ] != ktb[ idx ] ->getTextLng() ) text += "..";
-        tabwd[ idx ] = fm.width( text );
-        afterwd += tabwd[ idx ];
-
-        if ( afterwd >= parentWidth ) break;
-    }
-
-    /* set new texts */
-    if ( beforewd != afterwd && chgWidth ) {
-
-        for ( int i = 0; i < tabnum; ++i ) {
-
-            if ( lng[ i ] != ktb[ i ] ->text().length() ) {
-
-                QString fullText = ktb[ i ] ->getFullText();
-                if ( lng[ i ] < ktb[ i ] ->getTextLng() ) ktb[ i ] ->setText( fullText.left( lng[ i ] ) + ".." );
-                else ktb[ i ] ->setText( fullText );
-            }
-        }
-    }
-
-    delete lng;
-    delete ktb;
-    delete tabwd;
-    return chgWidth;
-}
-
-
-/* private */
-int KitaTabBarBase::getWidthOfTabs()
-{
-    int wd = 0;
-    for ( int i = 0; i < count(); ++i ) {
-        QTab* tb = tabAt( i );
-        wd += tb->rect().width();
-    }
-
-    return wd;
-}
-
-
-
-/*--------------------------------------------------------------------------------*/
-/*--------------------------------------------------------------------------------*/
-/*--------------------------------------------------------------------------------*/
-
-
-KitaTabBase::KitaTabBase( const QString & text ) : QTab( text )
-{
-    setFullText( text );
-}
-
-KitaTabBase::~KitaTabBase() {}
-
-
-/* public */
-QString KitaTabBase::getFullText() const
-{
-    return m_fullText;
-}
-
-
-/* public */
-const unsigned int KitaTabBase::getTextLng() const
-{
-    return m_textlng;
-}
-
-
-/* public */
-void KitaTabBase::setFullText( const QString& text )
-{
-    m_fullText = text;
-    m_textlng = text.length();
-}
-
-
 
 /*--------------------------------------------------------------------------------*/
 /*--------------------------------------------------------------------------------*/
 /*--------------------------------------------------------------------------------*/
 
 
-
 KitaDockWidgetBase::KitaDockWidgetBase( KDockManager* dockManager,
                                         const char* name,
                                         const QPixmap &pixmap,
@@ -817,15 +404,6 @@ KitaDockWidgetBase::KitaDockWidgetBase( KDockManager* dockManager,
     /* emit when this widget is deactivated */
     connect( this, SIGNAL( windowDeactivated() ),
              signalCollection, SIGNAL( windowDeactivated() ) );
-
-    /* If this widget is active and receives
-       signal isKitaActive, then emit signal kitaIsActive. */
-    /* see also KitaHTMLPart::slotOnURL                    */
-    connect( signalCollection, SIGNAL( isKitaActive() ),
-             this, SLOT( slotIsKitaActive() ) );
-
-    connect( this, SIGNAL( kitaIsActive() ),
-             signalCollection, SIGNAL( kitaIsActive() ) );
 }
 
 
@@ -938,8 +516,6 @@ void KitaDockWidgetBase::showDock( bool activate, bool force )
 
         if ( m_docked ) { /* This dock was docked to the other dock. */
 
-#if KDE_IS_VERSION( 3, 2, 0 )
-
             /* Sometimes the dock widget loses the former brother DockWidget.
                because the brogher widget had transformed. So, find and set new brogher widget here. */
 
@@ -961,7 +537,6 @@ void KitaDockWidgetBase::showDock( bool activate, bool force )
 
                 setFormerBrotherDockWidget( newBrsDock );
             }
-#endif
             makeDockVisible();
         } else show();
     }
@@ -1025,11 +600,3 @@ void KitaDockWidgetBase::customEvent( QCustomEvent * e )
         showDock( sde->getActivate(), sde->getForce() );
     }
 }
-
-
-/* see also KitaHTMLPart::slotOnURL */  /* private slot */
-void KitaDockWidgetBase::slotIsKitaActive()
-{
-    if ( isActiveWindow() ) emit kitaIsActive();
-}
-