summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/pwmviewstyle_0.cpp
blob: 1d88a34a89ec19763297a19533ff59f5edab85ae (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
134
135
136
137
138
139
140
141
142
143
144
/***************************************************************************
 *                                                                         *
 *   copyright (C) 2004 by Michael Buesch                                  *
 *   email: mbuesch@freenet.de                                             *
 *                                                                         *
 *   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.                         *
 *                                                                         *
 ***************************************************************************/

/***************************************************************************
 * copyright (C) 2004 by Ulf Schenk
 * This file is originaly based on version 1.0.1 of pwmanager
 * and was modified to run on embedded devices that run microkde
 *
 * $Id$
 **************************************************************************/  

#include "pwmviewstyle_0.h"
#include "pwmview.h"
#include "listviewpwm.h"
#include "commentbox.h"

#include <klocale.h>
#include <kglobal.h>
#include <kiconloader.h>
#include "pwmprefs.h"

PwMViewStyle_0::PwMViewStyle_0(PwMView *view)
 : QObject()
{
	vbox1 = new QVBox(view);
	vbox1->setSpacing(0);
	hbox1 = new QHBox(vbox1);
	hbox1->setSpacing(0);
	categoriesTitle = new QLabel(hbox1);
	categoriesTitle->setText(i18n("Category:"));
	categoriesCombo = new QComboBox(hbox1);
	categoriesCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,QSizePolicy::Preferred ));
	renCatButton = new QPushButton( hbox1);
    renCatButton->setPixmap (KGlobal::iconLoader()->loadIcon("edit", KIcon::Small) );
    int maxsi = renCatButton->sizeHint().height()+4;
    renCatButton->setMinimumSize( maxsi, maxsi );
	delCatButton = new QPushButton( hbox1);
    delCatButton->setPixmap (KGlobal::iconLoader()->loadIcon("editdelete", KIcon::Small) );
    maxsi = delCatButton->sizeHint().height()+4;
    delCatButton->setMinimumSize( maxsi, maxsi );
    delCatButton->setFocusPolicy( QWidget::NoFocus );
    renCatButton->setFocusPolicy( QWidget::NoFocus );
    
#ifndef PWM_EMBEDDED
	splitter1 = new QSplitter(vbox1);
	splitter1->setOrientation(Qt::Vertical);
#else
	splitter1 = new KDGanttMinimizeSplitter( Qt::Vertical, vbox1);
	splitter1->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );

	//US  topLayout->addWidget(mMiniSplitter );
#endif
	lv = new ListViewPwM(splitter1);
	commentBox = new CommentBox(splitter1);
	// set sizes and styles
	commentBox->resize(commentBox->size().width(), 60);
	categoriesTitle->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
	// connections
	connect(categoriesCombo, SIGNAL(activated(int)),
		view, SLOT(shiftToView()));
	connect(renCatButton, SIGNAL(clicked()),
		view, SLOT(renCatButton_slot()));
	connect(delCatButton, SIGNAL(clicked()),
		view, SLOT(delCatButton_slot()));
	connect(lv, SIGNAL(toggleOverview()),
		this, SLOT(toggleSplitter()));
}

PwMViewStyle_0::~PwMViewStyle_0()
{
	delete vbox1;
}
void PwMViewStyle_0::toggleSplitter()
{ 
    
    QValueList<int> si = splitter1->sizes();
    splitter1->toggle();
    QValueList<int> si2 = splitter1->sizes();
    //qDebug("PwMViewStyle_0::toggleSplitter() %d %d %d %d", si[0],si[1],si2[0],si2[1] );
    if ( si[0] == si2[0] && si[1] == si2[1] && si2[1] == 1 ) {
        int diff = si[0]/2;
        if ( diff > 200 )
            diff = 200;
        si[0] -= diff;
        si[1] += diff;
        splitter1->toggle();
        splitter1->setSizes( si );
    }

}

void PwMViewStyle_0::delCategory(const QString &cat)
{
	PWM_ASSERT(categoriesCombo);
	int i, count = categoriesCombo->count();
	for (i = 0; i < count; ++i) {
		if (categoriesCombo->text(i) == cat) {
			categoriesCombo->removeItem(i);
			return;
		}
	}
	BUG();
}

void PwMViewStyle_0::selectCategory(const QString &cat)
{
	PWM_ASSERT(categoriesCombo);
	int i, count = categoriesCombo->count();
	for (i = 0; i < count; ++i) {
		if (categoriesCombo->text(i) == cat) {
			categoriesCombo->setCurrentItem(i);
			return;
		}
	}
	// fall back to 0
	categoriesCombo->setCurrentItem(0);
}


//US ENH: I need a place to load the view dependend settings. Eg. splittersize
void PwMViewStyle_0::restoreSettings(PWMPrefs* prefs)
{
  //load and store the size of the listviewcolumns
  lv->restoreLayout(prefs->getConfig(), "listview");
  splitter1->setSizes( prefs->mCommentSplitter );
  commentBox->setFont( prefs->mViewFont );
}

//US ENH: I need a place to load the view dependend settings. Eg. splittersize
void PwMViewStyle_0::saveSettings(PWMPrefs* prefs)
{
  //store the size of the listviewcolumns
  lv->saveLayout(prefs->getConfig(), "listview");
  prefs->mCommentSplitter = splitter1->sizes();

}