Warning, file /office/calligra/libs/widgets/KoToolBoxDocker.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * Copyright (c) 2005-2009 Thomas Zander <zander@kde.org>
0003  * Copyright (c) 2009 Peter Simonsson <peter.simonsson@gmail.com>
0004  * Copyright (c) 2010 Cyrille Berger <cberger@cberger.net>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, write to
0018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020  */
0021 
0022 #include "KoToolBoxDocker_p.h"
0023 #include "KoToolBox_p.h"
0024 #include "KoToolBoxScrollArea_p.h"
0025 #include "KoDockWidgetTitleBar.h"
0026 #include "KoDockRegistry.h"
0027 #include <klocalizedstring.h>
0028 #include <QLabel>
0029 #include <QFontMetrics>
0030 #include <QFrame>
0031 
0032 KoToolBoxDocker::KoToolBoxDocker(KoToolBox *toolBox)
0033     : QDockWidget(i18n("Toolbox"))
0034     , m_toolBox(toolBox)
0035     , m_scrollArea(new KoToolBoxScrollArea(toolBox, this))
0036 {
0037     setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
0038     setWidget(m_scrollArea);
0039 
0040     // create title bar
0041     KoDockWidgetTitleBar* titleBar = new KoDockWidgetTitleBar(this);
0042     titleBar->setTextVisibilityMode(KoDockWidgetTitleBar::TextCanBeInvisible);
0043     titleBar->setToolTip(i18n("Tools"));
0044     setTitleBarWidget(titleBar);
0045 
0046     connect(this, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
0047             this, SLOT(updateToolBoxOrientation(Qt::DockWidgetArea)));
0048     connect(this, SIGNAL(topLevelChanged(bool)),
0049             this, SLOT(updateFloating(bool)));
0050 }
0051 
0052 void KoToolBoxDocker::setCanvas(KoCanvasBase *canvas)
0053 {
0054     Q_UNUSED(canvas);
0055 }
0056 
0057 void KoToolBoxDocker::unsetCanvas()
0058 {
0059 }
0060 
0061 void KoToolBoxDocker::resizeEvent(QResizeEvent *event)
0062 {
0063     QDockWidget::resizeEvent(event);
0064     if (isFloating()) {
0065         if (m_scrollArea->width() > m_scrollArea->height()) {
0066             m_scrollArea->setOrientation(Qt::Horizontal);
0067         } else {
0068             m_scrollArea->setOrientation(Qt::Vertical);
0069         }
0070     }
0071 }
0072 
0073 void KoToolBoxDocker::updateToolBoxOrientation(Qt::DockWidgetArea area)
0074 {
0075     if (area == Qt::TopDockWidgetArea || area == Qt::BottomDockWidgetArea) {
0076         m_scrollArea->setOrientation(Qt::Horizontal);
0077     } else {
0078         m_scrollArea->setOrientation(Qt::Vertical);
0079     }
0080 }
0081 
0082 void KoToolBoxDocker::updateFloating(bool v)
0083 {
0084     m_toolBox->setFloating(v);
0085 }