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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/***************************************************************************
* Copyright (C) 2005 by Alexander Nemish *
* *
* 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. *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <kdialog.h>
#include <klocale.h>
#include <tqvariant.h>
#include <tqpushbutton.h>
#include <tqheader.h>
#include <tqtable.h>
#include <layout.h>
#include <tqtooltip.h>
#include <tqwhatsthis.h>
#include "bookmarksdlg.h"
/*
* Constructs a BookmarksDlg as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* TRUE to construct a modal dialog.
*/
BookmarksDlg::BookmarksDlg(const Bookmarks& bms, TQWidget* parent,
const char* name, bool modal, WFlags fl)
: TQDialog(parent, name, modal, fl),
m_bookmarks(bms)
{
if ( !name )
setName( "BookmarksDlg" );
setSizeGripEnabled(TRUE);
BookmarksDlgLayout = new TQVBoxLayout( this, 11, 6, "BookmarksDlgLayout");
layout3 = new TQHBoxLayout( 0, 0, 6, "layout3");
bookmarksTable = new TQTable(3, 2, this, "bookmarksList" );
bookmarksTable->horizontalHeader()->setLabel(0, "Title");
bookmarksTable->horizontalHeader()->setLabel(1, "Page number");
// bookmarksTable->setLeftMargin(0);
bookmarksTable->setColumnStretchable(0, true);
bookmarksTable->setSelectionMode(TQTable::SingleRow);
layout3->addWidget( bookmarksTable );
layout2 = new TQVBoxLayout( 0, 0, 6, "layout2");
addButton = new TQPushButton( this, "addButton" );
layout2->addWidget( addButton );
deleteButton = new TQPushButton( this, "deleteButton" );
layout2->addWidget( deleteButton );
Horizontal_Spacing2_2 = new TQSpacerItem( 20, 60, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
layout2->addItem( Horizontal_Spacing2_2 );
layout3->addLayout( layout2 );
BookmarksDlgLayout->addLayout( layout3 );
Layout1 = new TQHBoxLayout( 0, 0, 6, "Layout1");
buttonHelp = new TQPushButton( this, "buttonHelp" );
buttonHelp->setAutoDefault( TRUE );
Layout1->addWidget( buttonHelp );
Horizontal_Spacing2 = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
Layout1->addItem( Horizontal_Spacing2 );
buttonOk = new TQPushButton( this, "buttonOk" );
buttonOk->setAutoDefault( TRUE );
buttonOk->setDefault( TRUE );
Layout1->addWidget( buttonOk );
buttonCancel = new TQPushButton( this, "buttonCancel" );
buttonCancel->setAutoDefault( TRUE );
Layout1->addWidget( buttonCancel );
BookmarksDlgLayout->addLayout( Layout1 );
languageChange();
resize( TQSize(400, 267).expandedTo(minimumSizeHint()) );
clearWState( WState_Polished );
updateBookmarks();
// signals and slots connections
connect(buttonOk, TQT_SIGNAL(clicked()), this, TQT_SLOT(accept()));
connect(buttonCancel, TQT_SIGNAL(clicked()), this, TQT_SLOT(reject()));
connect(addButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(addBookmark()));
connect(deleteButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(deleteBookmark()));
connect(bookmarksTable, TQT_SIGNAL(valueChanged(int, int)), this, TQT_SLOT(valueChanged(int, int)));
}
/*
* Destroys the object and frees any allocated resources
*/
BookmarksDlg::~BookmarksDlg()
{
// no need to delete child widgets, TQt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void BookmarksDlg::languageChange()
{
setCaption( tr2i18n( "Bookmarks editor" ) );
addButton->setText( tr2i18n( "Add" ) );
deleteButton->setText( tr2i18n( "Delete" ) );
buttonHelp->setText( tr2i18n( "&Help" ) );
buttonHelp->setAccel( TQKeySequence( tr2i18n( "F1" ) ) );
buttonOk->setText( tr2i18n( "&OK" ) );
buttonOk->setAccel( TQKeySequence( TQString() ) );
buttonCancel->setText( tr2i18n( "Ca&ncel" ) );
buttonCancel->setAccel( TQKeySequence( tr2i18n( "Alt+N" ) ) );
}
void BookmarksDlg::addBookmark()
{
m_bookmarks.push_back(Bookmark(2, "new bookmark"));
std::sort(m_bookmarks.begin(), m_bookmarks.end());
updateBookmarks();
}
void BookmarksDlg::deleteBookmark()
{
int row = bookmarksTable->currentRow();
if (row >= 0 && row < m_bookmarks.size())
{
m_bookmarks.erase(m_bookmarks.begin() + row);
updateBookmarks();
}
}
void BookmarksDlg::updateBookmarks()
{
bookmarksTable->setNumRows(0);
for (Bookmarks::size_type i = 0; i < m_bookmarks.size(); ++i)
{
const Bookmark& bm = m_bookmarks[i];
bookmarksTable->setNumRows(i+1);
bookmarksTable->setText(i, 0, bm.name());
bookmarksTable->setText(i, 1, TQString::number(bm.page()));
}
}
void BookmarksDlg::valueChanged(int row, int col)
{
if (row >= m_bookmarks.size()) return;
Bookmark& bm = m_bookmarks[row];
//Bookmark title
if (col == 0)
bm.setName(bookmarksTable->text(row, col));
//page number
else if (col == 1)
{
bool ok;
unsigned int page = bookmarksTable->text(row, col).toUInt(&ok);
if (ok)
bm.setPage(page);
else
//return old value
bookmarksTable->setText(row, col, TQString::number(bm.page()));
}
}
#include "bookmarksdlg.moc"
|