summaryrefslogtreecommitdiffstats
path: root/ksquirrel/sidebar/sq_multibar.cpp
blob: 3f1ba2768cf28710b5699f0fd8f68268dd3cf17b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/***************************************************************************
                          sq_multibar.cpp  -  description
                             -------------------
    begin                : ??? Nov 28 2005
    copyright            : (C) 2005 by Baryshev Dmitry
    email                : ksquirrel.iv@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <tqwidgetstack.h>
#include <tqsignalmapper.h>
#include <tqsplitter.h>

#include <kmultitabbar.h>
#include <kglobal.h>
#include <kiconloader.h>

#include "ksquirrel.h"
#include "sq_previewwidget.h"
#include "sq_multibar.h"
#include "sq_config.h"

SQ_MultiBar * SQ_MultiBar::m_inst = 0;

SQ_MultiBar::SQ_MultiBar(TQWidget *tqparent, const char *name) : TQHBox(tqparent, name)
{
    m_inst = this;
    m_id = 0;
    m_selected = -1;

    SQ_Config::instance()->setGroup("Interface");
    m_width = SQ_Config::instance()->readNumEntry("splitter", 220);

    mapper = new TQSignalMapper(TQT_TQOBJECT(this));

    connect(mapper, TQT_SIGNAL(mapped(int)), this, TQT_SLOT(raiseWidget(int)));

    mt = new KMultiTabBar(KMultiTabBar::Vertical, this);

    // setup multibar: style = VSNET, show text labels on the left side
    mt->setStyle(KMultiTabBar::VSNET);
    mt->setPosition(KMultiTabBar::Left);
    mt->showActiveTabTexts(true);

    setSpacing(0);

    TQSplitter   *ts = new TQSplitter(Qt::Vertical, this);
    ts->setOpaqueResize(false);

    // TQWigdetStack will contain all widgets
    stack = new TQWidgetStack(ts);

    new SQ_PreviewWidget(ts);

    TQValueList<int> sz;
    sz.append(5500);
    sz.append(4500);
    ts->setSizes(sz);
}

SQ_MultiBar::~SQ_MultiBar()
{}

void SQ_MultiBar::addWidget(TQWidget *new_w, const TQString &text, const TQString &icon)
{
    // add widget to stack
    stack->addWidget(new_w, m_id);

    // add button
    mt->appendTab(KGlobal::iconLoader()->loadIcon(icon, KIcon::Desktop, 22), m_id, text);

    // since we cann't determine which tab was clicked,
    // we should use TQSignalMapper to determine it.
    mapper->setMapping(TQT_TQOBJECT(mt->tab(m_id)), m_id);

    connect(mt->tab(m_id), TQT_SIGNAL(clicked()), mapper, TQT_SLOT(map()));

    m_id++;
}

void SQ_MultiBar::raiseWidget(int id)
{
    if(m_selected != -1)
        mt->setTab(m_selected, false);

    if(mt->isTabRaised(id))
    {
        if(m_selected != -1)
            m_width = stack->width();

        m_selected = id;

        setMinimumSize(TQSize(0, 0));
        setMaximumSize(TQSize(10000, 10000));
        stack->raiseWidget(id);
        stack->resize(m_width, stack->height());
        stack->show();

        SQ_PreviewWidget::instance()->ignore(false);
        SQ_PreviewWidget::instance()->loadPending();
    }
    else
    {
        SQ_PreviewWidget::instance()->ignore(true);

        KSquirrel::app()->saveLayout();

        m_selected = -1;
        m_width = stack->width();
        stack->hide();
        setFixedWidth(mt->width());
    }
}

void SQ_MultiBar::updateLayout()
{
    setFixedWidth(mt->tqsizeHint().width());
    stack->hide();
}

#include "sq_multibar.moc"