forked from ac001/ffs-central
-
Notifications
You must be signed in to change notification settings - Fork 1
/
opt_property.cpp
193 lines (157 loc) · 5.49 KB
/
opt_property.cpp
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*****************************************************************************
* ____ ____ _ _ _ *
* /# /_\_ | _ \ (_) __| | (_) ___ _ __ *
* | |/o\o\ | | | | | | / _` | | | / _ \ | '__| *
* | \\_/_/ | |_| | | | | (_| | | | | __/ | | *
* / |_ | |____/ |_| \__,_| |_| \___| |_| *
* | ||\_ ~| *
* | ||| \/ *
* | ||| Project : KFreeFlight : a KDE4 GUI frontend for FlightGear *
* \// | *
* || | Developper : Didier FABERT <[email protected]> *
* ||_ \ Date : 2009, April *
* \_| o| ,__, *
* \___/ Copyright (C) 2009 by didier fabert (oo)____ *
* ||||__ (__) )\ *
* (___)_) File : opt_property.cpp ||--|| * *
* *
* 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. *
*****************************************************************************/
#include "opt_property.h"
#include "settings.h"
#include <kactionselector.h>
#include <kmessagebox.h>
#include <kiconloader.h>
#include <kmenu.h>
#include <QLineEdit>
KFFOpt_property::KFFOpt_property( QWidget *parent )
: KFFOpt_skeleton( parent )
{
ui_widget.setupUi ( this );
wSetupHeader(ui_widget.wHeaderLabel);
m_available = ui_widget.selector->availableListWidget();
m_selected = ui_widget.selector->selectedListWidget();
m_available->setContextMenuPolicy( Qt::CustomContextMenu );
m_selected->setContextMenuPolicy( Qt::CustomContextMenu );
connect( m_available,
SIGNAL( customContextMenuRequested( const QPoint & ) ),
this,
SLOT( showAvailableMenu( const QPoint & ) )
);
connect( ui_widget.btn_add,
SIGNAL( clicked() ),
this,
SLOT( newAvailableITem() )
);
connect( ui_widget.edit,
SIGNAL( returnPressed() ),
this,
SLOT( newAvailableITem() )
);
//opt_othersopt
//selector_property
}
KFFOpt_property::~KFFOpt_property()
{
}
void KFFOpt_property::showAvailableMenu( const QPoint & pt )
{
QAction* editItem;
QAction* removeItem;
KMenu menu( this );
editItem = new QAction( tr2i18n( "Edit" ), this );
editItem->setStatusTip( tr2i18n( "Edit this property" ) );
connect( editItem, SIGNAL( triggered() ), this, SLOT( editAvailableITem() ) );
removeItem = new QAction( tr2i18n( "Remove" ), this );
removeItem->setStatusTip( tr2i18n( "Remove property from list" ) );
connect( removeItem, SIGNAL( triggered() ), this, SLOT( removeAvailableITem() ) );
menu.addAction( editItem );
menu.addSeparator();
menu.addAction( removeItem );
menu.exec( mapToGlobal( pt + ui_widget.selector->pos() + m_available->pos() ) );
}
void KFFOpt_property::newAvailableITem()
{
QListWidgetItem* item;
item = new QListWidgetItem( ui_widget.edit->text() );
m_available->addItem( item );
m_available->setCurrentItem( item );
ui_widget.edit->clear();
}
void KFFOpt_property::editAvailableITem()
{
QListWidgetItem* item;
item = m_available->currentItem();
ui_widget.edit->setText( item->text() );
delete item;
}
void KFFOpt_property::removeAvailableITem()
{
QListWidgetItem* item;
item = m_available->currentItem();
delete item;
}
void KFFOpt_property::saveSettings()
{
QListWidgetItem* item;
QStringList list;
int i = 0;
item = m_available->item( i );
while ( item )
{
list << item->text();
item = m_available->item( ++i );
}
Settings::setProperty_available( list );
i = 0;
list.clear();
item = m_selected->item( i );
while ( item )
{
list << item->text();
item = m_selected->item( ++i );
}
Settings::setProperty_selected( list );
Settings::self()->writeConfig();
}
void KFFOpt_property::loadSettings()
{
QStringList list;
QStringList::Iterator it;
QListWidgetItem* item;
m_available->clear();
list = Settings::property_available();
for ( it = list.begin() ; it != list.end() ; it++ )
{
item = new QListWidgetItem( *it );
m_available->addItem( item );
}
list.clear();
m_selected->clear();
list = Settings::property_selected();
for ( it = list.begin() ; it != list.end() ; it++ )
{
item = new QListWidgetItem( *it );
m_selected->addItem( item );
}
}
bool KFFOpt_property::getOptions( QStringList & list )
{
QListWidgetItem* item;
uint i = 0;
item = m_selected->item( i );
while ( item )
{
list << "--prop:" + item->text();
item = m_selected->item( ++i );
}
return true;
}