]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QRefDialog.C
renaming in frontends/qt4/ui: s/Q//g
[lyx.git] / src / frontends / qt4 / QRefDialog.C
1 /**
2  * \file QRefDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Kalle Dalheimer
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "QRefDialog.h"
15 #include "QRef.h"
16
17 #include <QLineEdit>
18 #include <QListWidget>
19 #include <QPushButton>
20 #include <QCloseEvent>
21
22 namespace lyx {
23 namespace frontend {
24
25 QRefDialog::QRefDialog(QRef * form)
26         : form_(form)
27 {
28         setupUi(this);
29
30         connect(okPB, SIGNAL(clicked()),
31                 form_, SLOT(slotOK()));
32         connect(applyPB, SIGNAL(clicked()),
33                 form_, SLOT(slotApply()));
34         connect(closePB, SIGNAL(clicked()),
35                 form_, SLOT(slotClose()));
36         connect(closePB, SIGNAL(clicked()),
37                 this, SLOT( reset_dialog() ) );
38
39         connect( typeCO, SIGNAL( activated(int) ), 
40                 this, SLOT( changed_adaptor() ) );
41         connect( referenceED, SIGNAL( textChanged(const QString&) ), 
42                 this, SLOT( changed_adaptor() ) );
43         connect( nameED, SIGNAL( textChanged(const QString&) ), 
44                 this, SLOT( changed_adaptor() ) );
45         connect( refsLW, SIGNAL(  itemClicked(QListWidgetItem *) ), 
46                 this, SLOT( refHighlighted(QListWidgetItem *) ) );
47         connect( refsLW, SIGNAL(  itemSelectionChanged() ),
48                 this, SLOT( selectionChanged() ) );
49         connect( refsLW, SIGNAL(  itemActivated(QListWidgetItem *) ), 
50                 this, SLOT( refSelected(QListWidgetItem *) ) );
51         connect( sortCB, SIGNAL( clicked(bool) ),
52                 this, SLOT( sortToggled(bool) ) );
53         connect( gotoPB, SIGNAL( clicked() ), 
54                 this, SLOT( gotoClicked() ) );
55         connect( updatePB, SIGNAL( clicked() ), 
56                 this, SLOT( updateClicked() ) );
57         connect( bufferCO, SIGNAL( activated(int) ), 
58                 this, SLOT( updateClicked() ) );
59
60         setFocusProxy(refsLW);
61 }
62
63 void QRefDialog::show()
64 {
65         QDialog::show();
66 }
67
68
69 void QRefDialog::changed_adaptor()
70 {
71         form_->changed();
72 }
73
74
75 void QRefDialog::gotoClicked()
76 {
77         form_->gotoRef();
78 }
79
80 void QRefDialog::selectionChanged()
81 {
82         if (form_->readOnly())
83                 return;
84         
85         QList<QListWidgetItem *> selections = refsLW->selectedItems();
86         if (selections.isEmpty())
87                 return;
88         QListWidgetItem * sel = selections.first();
89         refHighlighted(sel);
90         return;
91 }
92
93 void QRefDialog::refHighlighted(QListWidgetItem * sel)
94 {
95         if (form_->readOnly())
96                 return;
97
98 /*      int const cur_item = refsLW->currentRow();
99         bool const cur_item_selected = cur_item >= 0 ?
100                 refsLB->isSelected(cur_item) : false;*/
101         bool const cur_item_selected = refsLW->isItemSelected(sel);
102
103         if (cur_item_selected)
104                 referenceED->setText(sel->text());
105
106         if (form_->at_ref_)
107                 form_->gotoRef();
108         gotoPB->setEnabled(true);
109         if (form_->typeAllowed())
110                 typeCO->setEnabled(true);
111         if (form_->nameAllowed())
112                 nameED->setEnabled(true);
113 }
114
115
116 void QRefDialog::refSelected(QListWidgetItem * sel)
117 {
118         if (form_->readOnly())
119                 return;
120
121 /*      int const cur_item = refsLW->currentRow();
122         bool const cur_item_selected = cur_item >= 0 ?
123                 refsLB->isSelected(cur_item) : false;*/
124         bool const cur_item_selected = refsLW->isItemSelected(sel);
125
126         if (cur_item_selected)
127                 referenceED->setText(sel->text());
128         // <enter> or double click, inserts ref and closes dialog
129         form_->slotOK();
130 }
131
132
133 void QRefDialog::sortToggled(bool on)
134 {
135         form_->sort_ = on;
136         form_->redoRefs();
137 }
138
139
140 void QRefDialog::updateClicked()
141 {
142         form_->updateRefs();
143 }
144
145
146 void QRefDialog::reset_dialog() {
147         form_->at_ref_ = false;
148         form_->setGotoRef();
149 }
150
151
152 void QRefDialog::closeEvent(QCloseEvent * e)
153 {
154         form_->slotWMHide();
155         reset_dialog();
156         e->accept();
157 }
158
159 } // namespace frontend
160 } // namespace lyx
161
162 #include "QRefDialog_moc.cpp"