author | harlekin <harlekin> | 2002-08-01 00:47:09 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-08-01 00:47:09 (UTC) |
commit | ba034bf4cb91b83654056945fc27313a28528015 (patch) (unidiff) | |
tree | 4df33783ca21017424135aacc2e45b94437cfdff | |
parent | 26ff0c72228b9c89b079dfa381d448b6152eb408 (diff) | |
download | opie-ba034bf4cb91b83654056945fc27313a28528015.zip opie-ba034bf4cb91b83654056945fc27313a28528015.tar.gz opie-ba034bf4cb91b83654056945fc27313a28528015.tar.bz2 |
gcc3.x fixes
-rw-r--r-- | noncore/apps/opie-sheet/cellformat.cpp | 47 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/finddlg.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/mainwindow.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/numberdlg.cpp | 5 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sheet.cpp | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sortdlg.cpp | 5 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/textdlg.cpp | 5 | ||||
-rw-r--r-- | noncore/tools/remote/helptab.cpp | 2 | ||||
-rw-r--r-- | noncore/tools/remote/helptab.h | 7 | ||||
-rw-r--r-- | noncore/tools/remote/recorddialog.cpp | 9 | ||||
-rw-r--r-- | noncore/tools/remote/recorddialog.h | 8 |
11 files changed, 74 insertions, 32 deletions
diff --git a/noncore/apps/opie-sheet/cellformat.cpp b/noncore/apps/opie-sheet/cellformat.cpp index 597502c..342ebe9 100644 --- a/noncore/apps/opie-sheet/cellformat.cpp +++ b/noncore/apps/opie-sheet/cellformat.cpp | |||
@@ -1,599 +1,626 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | /* | 10 | /* |
11 | * Opie Sheet (formerly Sheet/Qt) | 11 | * Opie Sheet (formerly Sheet/Qt) |
12 | * by Serdar Ozler <sozler@sitebest.com> | 12 | * by Serdar Ozler <sozler@sitebest.com> |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include "cellformat.h" | 15 | #include "cellformat.h" |
16 | 16 | ||
17 | #include <qlistbox.h> | 17 | #include <qlistbox.h> |
18 | #include <qlabel.h> | 18 | #include <qlabel.h> |
19 | 19 | ||
20 | #define COMBO_WIDTHS 155 | 20 | #define COMBO_WIDTHS 155 |
21 | #define COMBO_HEIGHTS 21 | 21 | #define COMBO_HEIGHTS 21 |
22 | 22 | ||
23 | #define COLOR_COUNT 17 | 23 | #define COLOR_COUNT 17 |
24 | #define STYLE_COUNT 14 | 24 | #define STYLE_COUNT 14 |
25 | #define HALIGN_COUNT 3 | 25 | #define HALIGN_COUNT 3 |
26 | #define VALIGN_COUNT 3 | 26 | #define VALIGN_COUNT 3 |
27 | 27 | ||
28 | QColor qtColors[COLOR_COUNT]={Qt::black, Qt::white, Qt::darkGray, Qt::gray, Qt::lightGray, Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta, Qt::yellow, Qt::darkRed, Qt::darkGreen, Qt::darkBlue, Qt::darkCyan, Qt::darkMagenta, Qt::darkYellow}; | 28 | QColor qtColors[COLOR_COUNT]={Qt::black,Qt::white, Qt::darkGray, |
29 | Qt::BrushStyle brushStyles[STYLE_COUNT]={Qt::SolidPattern, Qt::Dense1Pattern, Qt::Dense2Pattern, Qt::Dense3Pattern, Qt::Dense4Pattern, Qt::Dense5Pattern, Qt::Dense6Pattern, Qt::Dense7Pattern, Qt::HorPattern, Qt::VerPattern, Qt::CrossPattern, Qt::BDiagPattern, Qt::FDiagPattern, Qt::DiagCrossPattern}; | 29 | Qt::gray, Qt::lightGray, Qt::red, |
30 | Qt::green, Qt::blue, Qt::cyan, | ||
31 | Qt::magenta, Qt::yellow, | ||
32 | Qt::darkRed, Qt::darkGreen, | ||
33 | Qt::darkBlue, Qt::darkCyan, | ||
34 | Qt::darkMagenta, Qt::darkYellow}; | ||
35 | |||
36 | Qt::BrushStyle brushStyles[STYLE_COUNT]={Qt::SolidPattern, | ||
37 | Qt::Dense1Pattern, Qt::Dense2Pattern, | ||
38 | Qt::Dense3Pattern, Qt::Dense4Pattern, | ||
39 | Qt::Dense5Pattern, Qt::Dense6Pattern, | ||
40 | Qt::Dense7Pattern, Qt::HorPattern, | ||
41 | Qt::VerPattern, Qt::CrossPattern, | ||
42 | Qt::BDiagPattern, Qt::FDiagPattern, | ||
43 | Qt::DiagCrossPattern}; | ||
44 | |||
30 | QString namesHAlign[HALIGN_COUNT]={"Left", "Right", "Center"}; | 45 | QString namesHAlign[HALIGN_COUNT]={"Left", "Right", "Center"}; |
31 | QString namesVAlign[VALIGN_COUNT]={"Top", "Bottom", "Center"}; | 46 | QString namesVAlign[VALIGN_COUNT]={"Top", "Bottom", "Center"}; |
32 | Qt::AlignmentFlags flagsHAlign[HALIGN_COUNT]={Qt::AlignLeft, Qt::AlignRight, Qt::AlignHCenter}; | ||
33 | Qt::AlignmentFlags flagsVAlign[VALIGN_COUNT]={Qt::AlignTop, Qt::AlignBottom, Qt::AlignVCenter}; | ||
34 | 47 | ||
35 | CellFormat::CellFormat(QWidget *parent=0) | 48 | Qt::AlignmentFlags flagsHAlign[HALIGN_COUNT]={Qt::AlignLeft, |
49 | Qt::AlignRight, | ||
50 | Qt::AlignHCenter}; | ||
51 | |||
52 | Qt::AlignmentFlags flagsVAlign[VALIGN_COUNT]={Qt::AlignTop, | ||
53 | Qt::AlignBottom, | ||
54 | Qt::AlignVCenter}; | ||
55 | |||
56 | CellFormat::CellFormat(QWidget *parent) | ||
36 | :QDialog(parent, 0, TRUE) | 57 | :QDialog(parent, 0, TRUE) |
37 | { | 58 | { |
38 | // Main widget | 59 | // Main widget |
39 | tabs=new QTabWidget(this); | 60 | tabs=new QTabWidget(this); |
40 | widgetBorders=new QWidget(tabs); | 61 | widgetBorders=new QWidget(tabs); |
41 | widgetBackground=new QWidget(tabs); | 62 | widgetBackground=new QWidget(tabs); |
42 | widgetFont=new QWidget(tabs); | 63 | widgetFont=new QWidget(tabs); |
43 | widgetAlignment=new QWidget(tabs); | 64 | widgetAlignment=new QWidget(tabs); |
44 | tabs->addTab(widgetBorders, tr("&Borders")); | 65 | tabs->addTab(widgetBorders, tr("&Borders")); |
45 | tabs->addTab(widgetBackground, tr("Back&ground")); | 66 | tabs->addTab(widgetBackground, tr("Back&ground")); |
46 | tabs->addTab(widgetFont, tr("&Font")); | 67 | tabs->addTab(widgetFont, tr("&Font")); |
47 | tabs->addTab(widgetAlignment, tr("&Alignment")); | 68 | tabs->addTab(widgetAlignment, tr("&Alignment")); |
48 | 69 | ||
49 | fontDB.loadRenderers(); | 70 | fontDB.loadRenderers(); |
50 | changedFont=changedAlign=changedBrush=FALSE; | 71 | changedFont=changedAlign=changedBrush=FALSE; |
51 | 72 | ||
52 | // Borders tab | 73 | // Borders tab |
53 | borderEditor=new BorderEditor(widgetBorders); | 74 | borderEditor=new BorderEditor(widgetBorders); |
54 | borderEditor->setGeometry(10, 10, 215, 145); | 75 | borderEditor->setGeometry(10, 10, 215, 145); |
55 | connect(borderEditor, SIGNAL(clicked(BorderEditor::BorderArea)), this, SLOT(borderClicked(BorderEditor::BorderArea))); | 76 | connect(borderEditor, SIGNAL(clicked(BorderEditor::BorderArea)), |
77 | this, SLOT(borderClicked(BorderEditor::BorderArea))); | ||
56 | 78 | ||
57 | comboBordersWidth=createCombo(COMBO_WIDTH, widgetBorders, tr("&Width:"), 165); | 79 | comboBordersWidth=createCombo(COMBO_WIDTH, widgetBorders, tr("&Width:"), 165); |
58 | comboBordersColor=createCombo(COMBO_COLOR, widgetBorders, tr("&Color:"), 165+(COMBO_HEIGHTS+10)); | 80 | comboBordersColor=createCombo(COMBO_COLOR, widgetBorders, tr("&Color:"), 165+(COMBO_HEIGHTS+10)); |
59 | 81 | ||
60 | buttonBordersDefaults=new QPushButton(tr("&Default Borders"), widgetBorders); | 82 | buttonBordersDefaults=new QPushButton(tr("&Default Borders"), widgetBorders); |
61 | buttonBordersDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); | 83 | buttonBordersDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), |
62 | connect(buttonBordersDefaults, SIGNAL(clicked()), this, SLOT(slotBordersDefaults())); | 84 | 110, COMBO_HEIGHTS); |
85 | |||
86 | connect(buttonBordersDefaults, SIGNAL(clicked()), | ||
87 | this, SLOT(slotBordersDefaults())); | ||
63 | 88 | ||
64 | // Background tab | 89 | // Background tab |
65 | frameBackground=new QFrame(widgetBackground); | 90 | frameBackground=new QFrame(widgetBackground); |
66 | frameBackground->setGeometry(10, 10, 215, 145); | 91 | frameBackground->setGeometry(10, 10, 215, 145); |
67 | frameBackground->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); | 92 | frameBackground->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); |
68 | 93 | ||
69 | comboBackgroundStyle=createCombo(COMBO_STYLE, widgetBackground, tr("&Style:"), 165); | 94 | comboBackgroundStyle=createCombo(COMBO_STYLE, widgetBackground, tr("&Style:"), 165); |
70 | connect(comboBackgroundStyle, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int))); | 95 | connect(comboBackgroundStyle, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int))); |
71 | comboBackgroundColor=createCombo(COMBO_COLOR, widgetBackground, tr("&Color:"), 165+(COMBO_HEIGHTS+10)); | 96 | comboBackgroundColor=createCombo(COMBO_COLOR, widgetBackground, tr("&Color:"), 165+(COMBO_HEIGHTS+10)); |
72 | connect(comboBackgroundColor, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int))); | 97 | connect(comboBackgroundColor, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int))); |
73 | 98 | ||
74 | buttonBackgroundDefaults=new QPushButton(tr("&Default Background"), widgetBackground); | 99 | buttonBackgroundDefaults=new QPushButton(tr("&Default Background"), widgetBackground); |
75 | buttonBackgroundDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); | 100 | buttonBackgroundDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); |
76 | connect(buttonBackgroundDefaults, SIGNAL(clicked()), this, SLOT(slotBackgroundDefaults())); | 101 | connect(buttonBackgroundDefaults, SIGNAL(clicked()), this, SLOT(slotBackgroundDefaults())); |
77 | 102 | ||
78 | // Font tab | 103 | // Font tab |
79 | frameFont=new QFrame(widgetFont); | 104 | frameFont=new QFrame(widgetFont); |
80 | frameFont->setGeometry(10, 10, 215, 125); | 105 | frameFont->setGeometry(10, 10, 215, 125); |
81 | frameFont->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); | 106 | frameFont->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); |
82 | 107 | ||
83 | comboFontFamily=createCombo(COMBO_FONT, widgetFont, tr("&Font:"), 145); | 108 | comboFontFamily=createCombo(COMBO_FONT, widgetFont, tr("&Font:"), 145); |
84 | connect(comboFontFamily, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); | 109 | connect(comboFontFamily, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); |
85 | comboFontSize=createCombo(COMBO_SIZE, widgetFont, tr("&Size:"), 145+(COMBO_HEIGHTS+10)); | 110 | comboFontSize=createCombo(COMBO_SIZE, widgetFont, tr("&Size:"), 145+(COMBO_HEIGHTS+10)); |
86 | connect(comboFontSize, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); | 111 | connect(comboFontSize, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); |
87 | comboFontColor=createCombo(COMBO_COLOR, widgetFont, tr("&Color:"), 145+2*(COMBO_HEIGHTS+10)); | 112 | comboFontColor=createCombo(COMBO_COLOR, widgetFont, tr("&Color:"), 145+2*(COMBO_HEIGHTS+10)); |
88 | connect(comboFontColor, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); | 113 | connect(comboFontColor, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); |
89 | 114 | ||
90 | checkFontBold=new QCheckBox(tr("&Bold"), widgetFont); | 115 | checkFontBold=new QCheckBox(tr("&Bold"), widgetFont); |
91 | checkFontBold->setGeometry(10, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS); | 116 | checkFontBold->setGeometry(10, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS); |
92 | connect(checkFontBold, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool))); | 117 | connect(checkFontBold, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool))); |
93 | checkFontItalic=new QCheckBox(tr("&Italic"), widgetFont); | 118 | checkFontItalic=new QCheckBox(tr("&Italic"), widgetFont); |
94 | checkFontItalic->setGeometry(60, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS); | 119 | checkFontItalic->setGeometry(60, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS); |
95 | connect(checkFontItalic, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool))); | 120 | connect(checkFontItalic, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool))); |
96 | 121 | ||
97 | buttonFontDefaults=new QPushButton(tr("&Default Font"), widgetFont); | 122 | buttonFontDefaults=new QPushButton(tr("&Default Font"), widgetFont); |
98 | buttonFontDefaults->setGeometry(115, 145+3*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); | 123 | buttonFontDefaults->setGeometry(115, 145+3*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); |
99 | connect(buttonFontDefaults, SIGNAL(clicked()), this, SLOT(slotFontDefaults())); | 124 | connect(buttonFontDefaults, SIGNAL(clicked()), this, SLOT(slotFontDefaults())); |
100 | 125 | ||
101 | // Alignment tab | 126 | // Alignment tab |
102 | frameAlignment=new QFrame(widgetAlignment); | 127 | frameAlignment=new QFrame(widgetAlignment); |
103 | frameAlignment->setGeometry(10, 10, 215, 145); | 128 | frameAlignment->setGeometry(10, 10, 215, 145); |
104 | frameAlignment->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); | 129 | frameAlignment->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); |
105 | 130 | ||
106 | comboAlignmentVertical=createCombo(COMBO_VALIGN, widgetAlignment, tr("&Vertical:"), 165); | 131 | comboAlignmentVertical=createCombo(COMBO_VALIGN, widgetAlignment, tr("&Vertical:"), 165); |
107 | connect(comboAlignmentVertical, SIGNAL(activated(int)), this, SLOT(alignClicked(int))); | 132 | connect(comboAlignmentVertical, SIGNAL(activated(int)), this, SLOT(alignClicked(int))); |
108 | comboAlignmentHorizontal=createCombo(COMBO_HALIGN, widgetAlignment, tr("&Horizontal:"), 165+(COMBO_HEIGHTS+10)); | 133 | comboAlignmentHorizontal=createCombo(COMBO_HALIGN, widgetAlignment, tr("&Horizontal:"), 165+(COMBO_HEIGHTS+10)); |
109 | connect(comboAlignmentHorizontal, SIGNAL(activated(int)), this, SLOT(alignClicked(int))); | 134 | connect(comboAlignmentHorizontal, SIGNAL(activated(int)), this, SLOT(alignClicked(int))); |
110 | 135 | ||
111 | checkAlignmentWrap=new QCheckBox(tr("&Word Wrap"), widgetAlignment); | 136 | checkAlignmentWrap=new QCheckBox(tr("&Word Wrap"), widgetAlignment); |
112 | checkAlignmentWrap->setGeometry(10, 165+2*(COMBO_HEIGHTS+10), 90, COMBO_HEIGHTS); | 137 | checkAlignmentWrap->setGeometry(10, 165+2*(COMBO_HEIGHTS+10), 90, COMBO_HEIGHTS); |
113 | connect(checkAlignmentWrap, SIGNAL(toggled(bool)), this, SLOT(alignClicked(bool))); | 138 | connect(checkAlignmentWrap, SIGNAL(toggled(bool)), this, SLOT(alignClicked(bool))); |
114 | 139 | ||
115 | buttonAlignmentDefaults=new QPushButton(tr("&Default Alignment"), widgetAlignment); | 140 | buttonAlignmentDefaults=new QPushButton(tr("&Default Alignment"), widgetAlignment); |
116 | buttonAlignmentDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); | 141 | buttonAlignmentDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); |
117 | connect(buttonAlignmentDefaults, SIGNAL(clicked()), this, SLOT(slotAlignmentDefaults())); | 142 | connect(buttonAlignmentDefaults, SIGNAL(clicked()), this, SLOT(slotAlignmentDefaults())); |
118 | 143 | ||
119 | // Main widget | 144 | // Main widget |
120 | box=new QVBoxLayout(this); | 145 | box=new QVBoxLayout(this); |
121 | box->addWidget(tabs); | 146 | box->addWidget(tabs); |
122 | 147 | ||
123 | setCaption(tr("Format Cells")); | 148 | setCaption(tr("Format Cells")); |
124 | } | 149 | } |
125 | 150 | ||
126 | CellFormat::~CellFormat() | 151 | CellFormat::~CellFormat() |
127 | { | 152 | { |
128 | } | 153 | } |
129 | 154 | ||
130 | int CellFormat::findColorIndex(const QColor &color) | 155 | int CellFormat::findColorIndex(const QColor &color) |
131 | { | 156 | { |
132 | for (int i=0; i<COLOR_COUNT; ++i) | 157 | for (int i=0; i<COLOR_COUNT; ++i) |
133 | if (qtColors[i]==color) | 158 | if (qtColors[i]==color) |
134 | return i; | 159 | return i; |
135 | return 0; | 160 | return 0; |
136 | } | 161 | } |
137 | 162 | ||
138 | int CellFormat::findVAlignIndex(Qt::AlignmentFlags flag) | 163 | int CellFormat::findVAlignIndex(Qt::AlignmentFlags flag) |
139 | { | 164 | { |
140 | for (int i=0; i<VALIGN_COUNT; ++i) | 165 | for (int i=0; i<VALIGN_COUNT; ++i) |
141 | if (flagsVAlign[i] & flag) | 166 | if (flagsVAlign[i] & flag) |
142 | return i; | 167 | return i; |
143 | return 0; | 168 | return 0; |
144 | } | 169 | } |
145 | 170 | ||
146 | int CellFormat::findHAlignIndex(Qt::AlignmentFlags flag) | 171 | int CellFormat::findHAlignIndex(Qt::AlignmentFlags flag) |
147 | { | 172 | { |
148 | for (int i=0; i<HALIGN_COUNT; ++i) | 173 | for (int i=0; i<HALIGN_COUNT; ++i) |
149 | if (flagsHAlign[i] & flag) | 174 | if (flagsHAlign[i] & flag) |
150 | return i; | 175 | return i; |
151 | return 0; | 176 | return 0; |
152 | } | 177 | } |
153 | 178 | ||
154 | int CellFormat::findBrushStyleIndex(Qt::BrushStyle style) | 179 | int CellFormat::findBrushStyleIndex(Qt::BrushStyle style) |
155 | { | 180 | { |
156 | for (int i=0; i<STYLE_COUNT; ++i) | 181 | for (int i=0; i<STYLE_COUNT; ++i) |
157 | if (brushStyles[i]==style) | 182 | if (brushStyles[i]==style) |
158 | return i; | 183 | return i; |
159 | return 0; | 184 | return 0; |
160 | } | 185 | } |
161 | 186 | ||
162 | void CellFormat::setBrushBackground(const QBrush &brush) | 187 | void CellFormat::setBrushBackground(const QBrush &brush) |
163 | { | 188 | { |
164 | comboBackgroundColor->setCurrentItem(findColorIndex(brush.color())); | 189 | comboBackgroundColor->setCurrentItem(findColorIndex(brush.color())); |
165 | comboBackgroundStyle->setCurrentItem(findBrushStyleIndex(brush.style())); | 190 | comboBackgroundStyle->setCurrentItem(findBrushStyleIndex(brush.style())); |
166 | 191 | ||
167 | QPixmap pix(frameBackground->contentsRect().width(), frameBackground->contentsRect().height()); | 192 | QPixmap pix(frameBackground->contentsRect().width(), frameBackground->contentsRect().height()); |
168 | QPainter p(&pix); | 193 | QPainter p(&pix); |
169 | pix.fill(); | 194 | pix.fill(); |
170 | p.fillRect(pix.rect(), brush); | 195 | p.fillRect(pix.rect(), brush); |
171 | frameBackground->setBackgroundPixmap(pix); | 196 | frameBackground->setBackgroundPixmap(pix); |
172 | 197 | ||
173 | brushBackground=brush; | 198 | brushBackground=brush; |
174 | } | 199 | } |
175 | 200 | ||
176 | void CellFormat::setTextFont(const QFont &font, const QColor &color) | 201 | void CellFormat::setTextFont(const QFont &font, const QColor &color) |
177 | { | 202 | { |
178 | comboFontColor->setCurrentItem(findColorIndex(color)); | 203 | comboFontColor->setCurrentItem(findColorIndex(color)); |
179 | comboFontFamily->setCurrentItem(findComboItemIndex(comboFontFamily, font.family())); | 204 | comboFontFamily->setCurrentItem(findComboItemIndex(comboFontFamily, font.family())); |
180 | comboFontSize->setCurrentItem(findComboItemIndex(comboFontSize, QString::number(font.pointSize()))); | 205 | comboFontSize->setCurrentItem(findComboItemIndex(comboFontSize, QString::number(font.pointSize()))); |
181 | checkFontBold->setChecked(font.weight()==QFont::Bold); | 206 | checkFontBold->setChecked(font.weight()==QFont::Bold); |
182 | checkFontItalic->setChecked(font.italic()); | 207 | checkFontItalic->setChecked(font.italic()); |
183 | 208 | ||
184 | QPixmap pix(frameFont->contentsRect().width(), frameFont->contentsRect().height()); | 209 | QPixmap pix(frameFont->contentsRect().width(), frameFont->contentsRect().height()); |
185 | QPainter p(&pix); | 210 | QPainter p(&pix); |
186 | pix.fill(); | 211 | pix.fill(); |
187 | p.fillRect(pix.rect(), Qt::white); | 212 | p.fillRect(pix.rect(), Qt::white); |
188 | p.setFont(font); | 213 | p.setFont(font); |
189 | p.setPen(color); | 214 | p.setPen(color); |
190 | p.drawText(pix.rect(), Qt::AlignCenter, tr("Opie Sheet")); | 215 | p.drawText(pix.rect(), Qt::AlignCenter, tr("Opie Sheet")); |
191 | frameFont->setBackgroundPixmap(pix); | 216 | frameFont->setBackgroundPixmap(pix); |
192 | 217 | ||
193 | fontFont=font; | 218 | fontFont=font; |
194 | fontColor=color; | 219 | fontColor=color; |
195 | } | 220 | } |
196 | 221 | ||
197 | void CellFormat::setTextAlign(Qt::AlignmentFlags flags) | 222 | void CellFormat::setTextAlign(Qt::AlignmentFlags flags) |
198 | { | 223 | { |
199 | comboAlignmentVertical->setCurrentItem(findVAlignIndex(flags)); | 224 | comboAlignmentVertical->setCurrentItem(findVAlignIndex(flags)); |
200 | comboAlignmentHorizontal->setCurrentItem(findHAlignIndex(flags)); | 225 | comboAlignmentHorizontal->setCurrentItem(findHAlignIndex(flags)); |
201 | checkAlignmentWrap->setChecked(flags & Qt::WordBreak); | 226 | checkAlignmentWrap->setChecked(flags & Qt::WordBreak); |
202 | 227 | ||
203 | QPixmap pix(frameAlignment->contentsRect().width(), frameAlignment->contentsRect().height()); | 228 | QPixmap pix(frameAlignment->contentsRect().width(), frameAlignment->contentsRect().height()); |
204 | QPainter p(&pix); | 229 | QPainter p(&pix); |
205 | pix.fill(); | 230 | pix.fill(); |
206 | p.fillRect(pix.rect(), Qt::white); | 231 | p.fillRect(pix.rect(), Qt::white); |
207 | p.drawText(10, 10, pix.width()-20, pix.height()-20, flags, tr("Opie Sheet")); | 232 | p.drawText(10, 10, pix.width()-20, pix.height()-20, flags, tr("Opie Sheet")); |
208 | frameAlignment->setBackgroundPixmap(pix); | 233 | frameAlignment->setBackgroundPixmap(pix); |
209 | 234 | ||
210 | textAlignment=flags; | 235 | textAlignment=flags; |
211 | } | 236 | } |
212 | 237 | ||
213 | void CellFormat::slotFontDefaults() | 238 | void CellFormat::slotFontDefaults() |
214 | { | 239 | { |
215 | changedFont=TRUE; | 240 | changedFont=TRUE; |
216 | setTextFont(font(), Qt::black); | 241 | setTextFont(font(), Qt::black); |
217 | } | 242 | } |
218 | 243 | ||
219 | void CellFormat::slotAlignmentDefaults() | 244 | void CellFormat::slotAlignmentDefaults() |
220 | { | 245 | { |
221 | changedAlign=TRUE; | 246 | changedAlign=TRUE; |
222 | setTextAlign((Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop)); | 247 | setTextAlign((Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop)); |
223 | } | 248 | } |
224 | 249 | ||
225 | void CellFormat::slotBackgroundDefaults() | 250 | void CellFormat::slotBackgroundDefaults() |
226 | { | 251 | { |
227 | changedBrush=TRUE; | 252 | changedBrush=TRUE; |
228 | setBrushBackground(Qt::white); | 253 | setBrushBackground(Qt::white); |
229 | } | 254 | } |
230 | 255 | ||
231 | void CellFormat::slotBordersDefaults() | 256 | void CellFormat::slotBordersDefaults() |
232 | { | 257 | { |
233 | QPen defaultPen(Qt::gray, 1, Qt::SolidLine); | 258 | QPen defaultPen(Qt::gray, 1, Qt::SolidLine); |
234 | borderEditor->setPen(defaultPen, BorderEditor::Top); | 259 | borderEditor->setPen(defaultPen, BorderEditor::Top); |
235 | borderEditor->setPen(defaultPen, BorderEditor::Bottom); | 260 | borderEditor->setPen(defaultPen, BorderEditor::Bottom); |
236 | borderEditor->setPen(defaultPen, BorderEditor::Left); | 261 | borderEditor->setPen(defaultPen, BorderEditor::Left); |
237 | borderEditor->setPen(defaultPen, BorderEditor::Right); | 262 | borderEditor->setPen(defaultPen, BorderEditor::Right); |
238 | borderEditor->setPen(defaultPen, BorderEditor::Vert); | 263 | borderEditor->setPen(defaultPen, BorderEditor::Vert); |
239 | borderEditor->setPen(defaultPen, BorderEditor::Horz); | 264 | borderEditor->setPen(defaultPen, BorderEditor::Horz); |
240 | } | 265 | } |
241 | 266 | ||
242 | void CellFormat::backgroundClicked(int index) | 267 | void CellFormat::backgroundClicked(int index) |
243 | { | 268 | { |
244 | changedBrush=TRUE; | 269 | changedBrush=TRUE; |
245 | setBrushBackground(QBrush(qtColors[comboBackgroundColor->currentItem()], brushStyles[comboBackgroundStyle->currentItem()])); | 270 | setBrushBackground(QBrush(qtColors[comboBackgroundColor->currentItem()], brushStyles[comboBackgroundStyle->currentItem()])); |
246 | } | 271 | } |
247 | 272 | ||
248 | void CellFormat::fontClicked(bool on) | 273 | void CellFormat::fontClicked(bool on) |
249 | { | 274 | { |
250 | fontClicked(0); | 275 | fontClicked(0); |
251 | } | 276 | } |
252 | 277 | ||
253 | void CellFormat::fontClicked(int index) | 278 | void CellFormat::fontClicked(int index) |
254 | { | 279 | { |
255 | changedFont=TRUE; | 280 | changedFont=TRUE; |
256 | setTextFont(QFont(comboFontFamily->currentText(), comboFontSize->currentText().toInt(), checkFontBold->isChecked() ? QFont::Bold : QFont::Normal, checkFontItalic->isChecked(), QFont::AnyCharSet), qtColors[comboFontColor->currentItem()]); | 281 | setTextFont(QFont(comboFontFamily->currentText(), comboFontSize->currentText().toInt(), checkFontBold->isChecked() ? QFont::Bold : QFont::Normal, checkFontItalic->isChecked(), QFont::AnyCharSet), qtColors[comboFontColor->currentItem()]); |
257 | } | 282 | } |
258 | 283 | ||
259 | void CellFormat::alignClicked(bool on) | 284 | void CellFormat::alignClicked(bool on) |
260 | { | 285 | { |
261 | alignClicked(0); | 286 | alignClicked(0); |
262 | } | 287 | } |
263 | 288 | ||
264 | void CellFormat::alignClicked(int index) | 289 | void CellFormat::alignClicked(int index) |
265 | { | 290 | { |
266 | changedAlign=TRUE; | 291 | changedAlign=TRUE; |
267 | setTextAlign((Qt::AlignmentFlags)(flagsVAlign[comboAlignmentVertical->currentItem()] | flagsHAlign[comboAlignmentHorizontal->currentItem()] | (checkAlignmentWrap->isChecked() ? Qt::WordBreak : 0))); | 292 | setTextAlign((Qt::AlignmentFlags)(flagsVAlign[comboAlignmentVertical->currentItem()] | flagsHAlign[comboAlignmentHorizontal->currentItem()] | (checkAlignmentWrap->isChecked() ? Qt::WordBreak : 0))); |
268 | } | 293 | } |
269 | 294 | ||
270 | void CellFormat::createSizeCombo(QComboBox *combo) | 295 | void CellFormat::createSizeCombo(QComboBox *combo) |
271 | { | 296 | { |
272 | combo->clear(); | 297 | combo->clear(); |
273 | QValueList<int> sizes=fontDB.standardSizes(); | 298 | QValueList<int> sizes=fontDB.standardSizes(); |
274 | for (QValueList<int>::ConstIterator i=sizes.begin(); i!=sizes.end(); ++i) | 299 | for (QValueList<int>::ConstIterator i=sizes.begin(); i!=sizes.end(); ++i) |
275 | combo->insertItem(QString::number(*i)); | 300 | combo->insertItem(QString::number(*i)); |
276 | } | 301 | } |
277 | 302 | ||
278 | void CellFormat::borderClicked(BorderEditor::BorderArea area) | 303 | void CellFormat::borderClicked(BorderEditor::BorderArea area) |
279 | { | 304 | { |
280 | QPen newPen(qtColors[comboBordersColor->currentItem()], comboBordersWidth->currentItem()+1, Qt::SolidLine); | 305 | QPen newPen(qtColors[comboBordersColor->currentItem()], comboBordersWidth->currentItem()+1, Qt::SolidLine); |
281 | if (newPen==borderEditor->getPen(area)) | 306 | if (newPen==borderEditor->getPen(area)) |
282 | borderEditor->setPen(QPen(Qt::gray, 1, Qt::NoPen), area); | 307 | borderEditor->setPen(QPen(Qt::gray, 1, Qt::NoPen), area); |
283 | else | 308 | else |
284 | borderEditor->setPen(newPen, area); | 309 | borderEditor->setPen(newPen, area); |
285 | } | 310 | } |
286 | 311 | ||
287 | int CellFormat::findComboItemIndex(QComboBox *combo, const QString &item) | 312 | int CellFormat::findComboItemIndex(QComboBox *combo, const QString &item) |
288 | { | 313 | { |
289 | for (int i=0; i<combo->count(); ++i) | 314 | for (int i=0; i<combo->count(); ++i) |
290 | if (combo->text(i)==item) | 315 | if (combo->text(i)==item) |
291 | return i; | 316 | return i; |
292 | return 0; | 317 | return 0; |
293 | } | 318 | } |
294 | 319 | ||
295 | QComboBox *CellFormat::createCombo(comboType type, QWidget *parent, const QString &caption, int y) | 320 | QComboBox *CellFormat::createCombo(comboType type, QWidget *parent, |
321 | const QString &caption, int y) | ||
296 | { | 322 | { |
297 | QComboBox *combo=new QComboBox(FALSE, parent); | 323 | QComboBox *combo=new QComboBox(FALSE, parent); |
298 | combo->setGeometry(70, y, COMBO_WIDTHS, COMBO_HEIGHTS); | 324 | combo->setGeometry(70, y, COMBO_WIDTHS, COMBO_HEIGHTS); |
299 | combo->setSizeLimit(5); | 325 | combo->setSizeLimit(5); |
300 | 326 | ||
301 | switch (type) | 327 | switch (type) |
302 | { | 328 | { |
303 | case COMBO_WIDTH: createWidthCombo(combo); break; | 329 | case COMBO_WIDTH: createWidthCombo(combo); break; |
304 | case COMBO_STYLE: createStyleCombo(combo); break; | 330 | case COMBO_STYLE: createStyleCombo(combo); break; |
305 | case COMBO_FONT: createFontCombo(combo); break; | 331 | case COMBO_FONT: createFontCombo(combo); break; |
306 | case COMBO_SIZE: createSizeCombo(combo); break; | 332 | case COMBO_SIZE: createSizeCombo(combo); break; |
307 | case COMBO_COLOR: createColorCombo(combo); break; | 333 | case COMBO_COLOR: createColorCombo(combo); break; |
308 | case COMBO_HALIGN: createHAlignCombo(combo); break; | 334 | case COMBO_HALIGN: createHAlignCombo(combo); break; |
309 | case COMBO_VALIGN: createVAlignCombo(combo); break; | 335 | case COMBO_VALIGN: createVAlignCombo(combo); break; |
336 | default: break; | ||
310 | } | 337 | } |
311 | 338 | ||
312 | QLabel *label=new QLabel(combo, caption, parent); | 339 | QLabel *label=new QLabel(combo, caption, parent); |
313 | label->setGeometry(10, y, 50, COMBO_HEIGHTS); | 340 | label->setGeometry(10, y, 50, COMBO_HEIGHTS); |
314 | 341 | ||
315 | return combo; | 342 | return combo; |
316 | } | 343 | } |
317 | 344 | ||
318 | void CellFormat::createHAlignCombo(QComboBox *combo) | 345 | void CellFormat::createHAlignCombo(QComboBox *combo) |
319 | { | 346 | { |
320 | for (int i=0; i<HALIGN_COUNT; ++i) | 347 | for (int i=0; i<HALIGN_COUNT; ++i) |
321 | combo->insertItem(namesHAlign[i]); | 348 | combo->insertItem(namesHAlign[i]); |
322 | } | 349 | } |
323 | 350 | ||
324 | void CellFormat::createVAlignCombo(QComboBox *combo) | 351 | void CellFormat::createVAlignCombo(QComboBox *combo) |
325 | { | 352 | { |
326 | for (int i=0; i<VALIGN_COUNT; ++i) | 353 | for (int i=0; i<VALIGN_COUNT; ++i) |
327 | combo->insertItem(namesVAlign[i]); | 354 | combo->insertItem(namesVAlign[i]); |
328 | } | 355 | } |
329 | 356 | ||
330 | void CellFormat::createWidthCombo(QComboBox *combo) | 357 | void CellFormat::createWidthCombo(QComboBox *combo) |
331 | { | 358 | { |
332 | int width=combo->listBox()->maxItemWidth(); | 359 | int width=combo->listBox()->maxItemWidth(); |
333 | QPixmap pix(width, COMBO_HEIGHTS); | 360 | QPixmap pix(width, COMBO_HEIGHTS); |
334 | QPainter p(&pix); | 361 | QPainter p(&pix); |
335 | 362 | ||
336 | for (int i=1; i<=6; ++i) | 363 | for (int i=1; i<=6; ++i) |
337 | { | 364 | { |
338 | pix.fill(); | 365 | pix.fill(); |
339 | p.setPen(QPen(Qt::black, i, Qt::SolidLine)); | 366 | p.setPen(QPen(Qt::black, i, Qt::SolidLine)); |
340 | p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2); | 367 | p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2); |
341 | combo->insertItem(pix); | 368 | combo->insertItem(pix); |
342 | } | 369 | } |
343 | } | 370 | } |
344 | 371 | ||
345 | void CellFormat::createFontCombo(QComboBox *combo) | 372 | void CellFormat::createFontCombo(QComboBox *combo) |
346 | { | 373 | { |
347 | combo->insertStringList(fontDB.families()); | 374 | combo->insertStringList(fontDB.families()); |
348 | } | 375 | } |
349 | 376 | ||
350 | void CellFormat::createStyleCombo(QComboBox *combo) | 377 | void CellFormat::createStyleCombo(QComboBox *combo) |
351 | { | 378 | { |
352 | int width=combo->listBox()->maxItemWidth(); | 379 | int width=combo->listBox()->maxItemWidth(); |
353 | QPixmap pix(width, COMBO_HEIGHTS); | 380 | QPixmap pix(width, COMBO_HEIGHTS); |
354 | QPainter p(&pix); | 381 | QPainter p(&pix); |
355 | 382 | ||
356 | for (int i=0; i<STYLE_COUNT; ++i) | 383 | for (int i=0; i<STYLE_COUNT; ++i) |
357 | { | 384 | { |
358 | pix.fill(); | 385 | pix.fill(); |
359 | p.fillRect(5, 5, width-10, COMBO_HEIGHTS-10, brushStyles[i]); | 386 | p.fillRect(5, 5, width-10, COMBO_HEIGHTS-10, brushStyles[i]); |
360 | combo->insertItem(pix); | 387 | combo->insertItem(pix); |
361 | } | 388 | } |
362 | } | 389 | } |
363 | 390 | ||
364 | void CellFormat::createColorCombo(QComboBox *combo) | 391 | void CellFormat::createColorCombo(QComboBox *combo) |
365 | { | 392 | { |
366 | int width=combo->listBox()->maxItemWidth(); | 393 | int width=combo->listBox()->maxItemWidth(); |
367 | QPixmap pix(width, COMBO_HEIGHTS); | 394 | QPixmap pix(width, COMBO_HEIGHTS); |
368 | QPainter p(&pix); | 395 | QPainter p(&pix); |
369 | 396 | ||
370 | for (int i=0; i<COLOR_COUNT; ++i) | 397 | for (int i=0; i<COLOR_COUNT; ++i) |
371 | { | 398 | { |
372 | pix.fill(); | 399 | pix.fill(); |
373 | p.setPen(QPen(qtColors[i], 3, Qt::SolidLine)); | 400 | p.setPen(QPen(qtColors[i], 3, Qt::SolidLine)); |
374 | p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2); | 401 | p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2); |
375 | combo->insertItem(pix); | 402 | combo->insertItem(pix); |
376 | } | 403 | } |
377 | } | 404 | } |
378 | 405 | ||
379 | int CellFormat::exec(Sheet *s) | 406 | int CellFormat::exec(Sheet *s) |
380 | { | 407 | { |
381 | sheet=s; | 408 | sheet=s; |
382 | int row1, row2, col1, col2, row, col; | 409 | int row1, row2, col1, col2, row, col; |
383 | sheet->getSelection(&row1, &col1, &row2, &col2); | 410 | sheet->getSelection(&row1, &col1, &row2, &col2); |
384 | 411 | ||
385 | QPen penTop=sheet->getPen(row1-1, col1, 0), penBottom=sheet->getPen(row2, col1, 0), | 412 | QPen penTop=sheet->getPen(row1-1, col1, 0), penBottom=sheet->getPen(row2, col1, 0), |
386 | penLeft=sheet->getPen(row1, col1-1, 1), penRight=sheet->getPen(row1, col2, 1), | 413 | penLeft=sheet->getPen(row1, col1-1, 1), penRight=sheet->getPen(row1, col2, 1), |
387 | penVert=sheet->getPen(row1, col1, 1), penHorz=sheet->getPen(row1, col1, 0), | 414 | penVert=sheet->getPen(row1, col1, 1), penHorz=sheet->getPen(row1, col1, 0), |
388 | penDefault=borderEditor->getDefaultPen(); | 415 | penDefault=borderEditor->getDefaultPen(); |
389 | for (row=row1+1; row<=row2; ++row) | 416 | for (row=row1+1; row<=row2; ++row) |
390 | if (sheet->getPen(row, col1-1, 1)!=penLeft) | 417 | if (sheet->getPen(row, col1-1, 1)!=penLeft) |
391 | { | 418 | { |
392 | penLeft=penDefault; | 419 | penLeft=penDefault; |
393 | break; | 420 | break; |
394 | } | 421 | } |
395 | for (row=row1+1; row<=row2; ++row) | 422 | for (row=row1+1; row<=row2; ++row) |
396 | if (sheet->getPen(row, col2, 1)!=penRight) | 423 | if (sheet->getPen(row, col2, 1)!=penRight) |
397 | { | 424 | { |
398 | penRight=penDefault; | 425 | penRight=penDefault; |
399 | break; | 426 | break; |
400 | } | 427 | } |
401 | for (col=col1+1; col<=col2; ++col) | 428 | for (col=col1+1; col<=col2; ++col) |
402 | if (sheet->getPen(row1-1, col, 0)!=penTop) | 429 | if (sheet->getPen(row1-1, col, 0)!=penTop) |
403 | { | 430 | { |
404 | penTop=penDefault; | 431 | penTop=penDefault; |
405 | break; | 432 | break; |
406 | } | 433 | } |
407 | for (col=col1+1; col<=col2; ++col) | 434 | for (col=col1+1; col<=col2; ++col) |
408 | if (sheet->getPen(row2, col, 0)!=penBottom) | 435 | if (sheet->getPen(row2, col, 0)!=penBottom) |
409 | { | 436 | { |
410 | penBottom=penDefault; | 437 | penBottom=penDefault; |
411 | break; | 438 | break; |
412 | } | 439 | } |
413 | for (row=row1; row<=row2; ++row) | 440 | for (row=row1; row<=row2; ++row) |
414 | for (col=col1; col<col2; ++col) | 441 | for (col=col1; col<col2; ++col) |
415 | if (sheet->getPen(row, col, 1)!=penVert) | 442 | if (sheet->getPen(row, col, 1)!=penVert) |
416 | { | 443 | { |
417 | penVert=penDefault; | 444 | penVert=penDefault; |
418 | break; | 445 | break; |
419 | } | 446 | } |
420 | for (row=row1; row<row2; ++row) | 447 | for (row=row1; row<row2; ++row) |
421 | for (col=col1; col<=col2; ++col) | 448 | for (col=col1; col<=col2; ++col) |
422 | if (sheet->getPen(row, col, 0)!=penHorz) | 449 | if (sheet->getPen(row, col, 0)!=penHorz) |
423 | { | 450 | { |
424 | penHorz=penDefault; | 451 | penHorz=penDefault; |
425 | break; | 452 | break; |
426 | } | 453 | } |
427 | 454 | ||
428 | borderEditor->setPen(penTop, BorderEditor::Top); | 455 | borderEditor->setPen(penTop, BorderEditor::Top); |
429 | borderEditor->setPen(penBottom, BorderEditor::Bottom); | 456 | borderEditor->setPen(penBottom, BorderEditor::Bottom); |
430 | borderEditor->setPen(penLeft, BorderEditor::Left); | 457 | borderEditor->setPen(penLeft, BorderEditor::Left); |
431 | borderEditor->setPen(penRight, BorderEditor::Right); | 458 | borderEditor->setPen(penRight, BorderEditor::Right); |
432 | borderEditor->setPen(penVert, BorderEditor::Vert); | 459 | borderEditor->setPen(penVert, BorderEditor::Vert); |
433 | borderEditor->setPen(penHorz, BorderEditor::Horz); | 460 | borderEditor->setPen(penHorz, BorderEditor::Horz); |
434 | 461 | ||
435 | setBrushBackground(sheet->getBrush(row1, col1)); | 462 | setBrushBackground(sheet->getBrush(row1, col1)); |
436 | setTextFont(sheet->getFont(row1, col1), sheet->getFontColor(row1, col1)); | 463 | setTextFont(sheet->getFont(row1, col1), sheet->getFontColor(row1, col1)); |
437 | setTextAlign(sheet->getAlignment(row1, col1)); | 464 | setTextAlign(sheet->getAlignment(row1, col1)); |
438 | 465 | ||
439 | if (QDialog::exec()==QDialog::Accepted) | 466 | if (QDialog::exec()==QDialog::Accepted) |
440 | { | 467 | { |
441 | penTop=borderEditor->getPen(BorderEditor::Top); | 468 | penTop=borderEditor->getPen(BorderEditor::Top); |
442 | penBottom=borderEditor->getPen(BorderEditor::Bottom); | 469 | penBottom=borderEditor->getPen(BorderEditor::Bottom); |
443 | penLeft=borderEditor->getPen(BorderEditor::Left); | 470 | penLeft=borderEditor->getPen(BorderEditor::Left); |
444 | penRight=borderEditor->getPen(BorderEditor::Right); | 471 | penRight=borderEditor->getPen(BorderEditor::Right); |
445 | penVert=borderEditor->getPen(BorderEditor::Vert); | 472 | penVert=borderEditor->getPen(BorderEditor::Vert); |
446 | penHorz=borderEditor->getPen(BorderEditor::Horz); | 473 | penHorz=borderEditor->getPen(BorderEditor::Horz); |
447 | 474 | ||
448 | if (penTop!=penDefault) | 475 | if (penTop!=penDefault) |
449 | for (col=col1; col<=col2; ++col) | 476 | for (col=col1; col<=col2; ++col) |
450 | sheet->setPen(row1-1, col, 0, penTop); | 477 | sheet->setPen(row1-1, col, 0, penTop); |
451 | if (penBottom!=penDefault) | 478 | if (penBottom!=penDefault) |
452 | for (col=col1; col<=col2; ++col) | 479 | for (col=col1; col<=col2; ++col) |
453 | sheet->setPen(row2, col, 0, penBottom); | 480 | sheet->setPen(row2, col, 0, penBottom); |
454 | if (penLeft!=penDefault) | 481 | if (penLeft!=penDefault) |
455 | for (row=row1; row<=row2; ++row) | 482 | for (row=row1; row<=row2; ++row) |
456 | sheet->setPen(row, col1-1, 1, penLeft); | 483 | sheet->setPen(row, col1-1, 1, penLeft); |
457 | if (penRight!=penDefault) | 484 | if (penRight!=penDefault) |
458 | for (row=row1; row<=row2; ++row) | 485 | for (row=row1; row<=row2; ++row) |
459 | sheet->setPen(row, col2, 1, penRight); | 486 | sheet->setPen(row, col2, 1, penRight); |
460 | if (penVert!=penDefault) | 487 | if (penVert!=penDefault) |
461 | for (row=row1; row<=row2; ++row) | 488 | for (row=row1; row<=row2; ++row) |
462 | for (col=col1; col<col2; ++col) | 489 | for (col=col1; col<col2; ++col) |
463 | sheet->setPen(row, col, 1, penVert); | 490 | sheet->setPen(row, col, 1, penVert); |
464 | if (penHorz!=penDefault) | 491 | if (penHorz!=penDefault) |
465 | for (row=row1; row<row2; ++row) | 492 | for (row=row1; row<row2; ++row) |
466 | for (col=col1; col<=col2; ++col) | 493 | for (col=col1; col<=col2; ++col) |
467 | sheet->setPen(row, col, 0, penHorz); | 494 | sheet->setPen(row, col, 0, penHorz); |
468 | 495 | ||
469 | if (changedBrush) | 496 | if (changedBrush) |
470 | { | 497 | { |
471 | for (row=row1; row<=row2; ++row) | 498 | for (row=row1; row<=row2; ++row) |
472 | for (col=col1; col<=col2; ++col) | 499 | for (col=col1; col<=col2; ++col) |
473 | sheet->setBrush(row, col, brushBackground); | 500 | sheet->setBrush(row, col, brushBackground); |
474 | } | 501 | } |
475 | 502 | ||
476 | if (changedAlign) | 503 | if (changedAlign) |
477 | { | 504 | { |
478 | for (row=row1; row<=row2; ++row) | 505 | for (row=row1; row<=row2; ++row) |
479 | for (col=col1; col<=col2; ++col) | 506 | for (col=col1; col<=col2; ++col) |
480 | sheet->setTextAlign(row, col, textAlignment); | 507 | sheet->setTextAlign(row, col, textAlignment); |
481 | } | 508 | } |
482 | 509 | ||
483 | if (changedFont) | 510 | if (changedFont) |
484 | { | 511 | { |
485 | for (row=row1; row<=row2; ++row) | 512 | for (row=row1; row<=row2; ++row) |
486 | for (col=col1; col<=col2; ++col) | 513 | for (col=col1; col<=col2; ++col) |
487 | sheet->setTextFont(row, col, fontFont, fontColor); | 514 | sheet->setTextFont(row, col, fontFont, fontColor); |
488 | } | 515 | } |
489 | return QDialog::Accepted; | 516 | return QDialog::Accepted; |
490 | } | 517 | } |
491 | return QDialog::Rejected; | 518 | return QDialog::Rejected; |
492 | } | 519 | } |
493 | 520 | ||
494 | // | 521 | // |
495 | // Border Editor | 522 | // Border Editor |
496 | // | 523 | // |
497 | 524 | ||
498 | BorderEditor::BorderEditor(QWidget *parent=0) | 525 | BorderEditor::BorderEditor(QWidget *parent) |
499 | :QFrame(parent) | 526 | :QFrame(parent) |
500 | { | 527 | { |
501 | setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); | 528 | setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); |
502 | } | 529 | } |
503 | 530 | ||
504 | BorderEditor::~BorderEditor() | 531 | BorderEditor::~BorderEditor() |
505 | { | 532 | { |
506 | } | 533 | } |
507 | 534 | ||
508 | void BorderEditor::drawContents(QPainter *p) | 535 | void BorderEditor::drawContents(QPainter *p) |
509 | { | 536 | { |
510 | QFrame::drawContents(p); | 537 | QFrame::drawContents(p); |
511 | 538 | ||
512 | int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3; | 539 | int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3; |
513 | int lineFirstX=x+width/6, lineFirstY=y+height/6, lineLastX=contentsRect().right()-width/6, lineLastY=contentsRect().bottom()-height/6; | 540 | int lineFirstX=x+width/6, lineFirstY=y+height/6, lineLastX=contentsRect().right()-width/6, lineLastY=contentsRect().bottom()-height/6; |
514 | 541 | ||
515 | p->fillRect(contentsRect(), Qt::white); | 542 | p->fillRect(contentsRect(), Qt::white); |
516 | 543 | ||
517 | p->fillRect(x+width/3, y+height/3, width, height, Qt::gray); | 544 | p->fillRect(x+width/3, y+height/3, width, height, Qt::gray); |
518 | p->fillRect(x+(5*width/3), y+height/3, width, height, Qt::gray); | 545 | p->fillRect(x+(5*width/3), y+height/3, width, height, Qt::gray); |
519 | p->fillRect(x+width/3, y+(5*height)/3, width, height, Qt::gray); | 546 | p->fillRect(x+width/3, y+(5*height)/3, width, height, Qt::gray); |
520 | p->fillRect(x+(5*width)/3, y+(5*height)/3, width, height, Qt::gray); | 547 | p->fillRect(x+(5*width)/3, y+(5*height)/3, width, height, Qt::gray); |
521 | 548 | ||
522 | if (penTop.width()>0) | 549 | if (penTop.width()>0) |
523 | { | 550 | { |
524 | p->setPen(penTop); | 551 | p->setPen(penTop); |
525 | p->drawLine(lineFirstX, lineFirstY, lineLastX, lineFirstY); | 552 | p->drawLine(lineFirstX, lineFirstY, lineLastX, lineFirstY); |
526 | } | 553 | } |
527 | if (penBottom.width()>0) | 554 | if (penBottom.width()>0) |
528 | { | 555 | { |
529 | p->setPen(penBottom); | 556 | p->setPen(penBottom); |
530 | p->drawLine(lineFirstX, lineLastY, lineLastX, lineLastY); | 557 | p->drawLine(lineFirstX, lineLastY, lineLastX, lineLastY); |
531 | } | 558 | } |
532 | if (penHorz.width()>0) | 559 | if (penHorz.width()>0) |
533 | { | 560 | { |
534 | p->setPen(penHorz); | 561 | p->setPen(penHorz); |
535 | p->drawLine(lineFirstX, y+contentsRect().height()/2, lineLastX, y+contentsRect().height()/2); | 562 | p->drawLine(lineFirstX, y+contentsRect().height()/2, lineLastX, y+contentsRect().height()/2); |
536 | } | 563 | } |
537 | if (penLeft.width()>0) | 564 | if (penLeft.width()>0) |
538 | { | 565 | { |
539 | p->setPen(penLeft); | 566 | p->setPen(penLeft); |
540 | p->drawLine(lineFirstX, lineFirstY, lineFirstX, lineLastY); | 567 | p->drawLine(lineFirstX, lineFirstY, lineFirstX, lineLastY); |
541 | } | 568 | } |
542 | if (penRight.width()>0) | 569 | if (penRight.width()>0) |
543 | { | 570 | { |
544 | p->setPen(penRight); | 571 | p->setPen(penRight); |
545 | p->drawLine(lineLastX, lineFirstY, lineLastX, lineLastY); | 572 | p->drawLine(lineLastX, lineFirstY, lineLastX, lineLastY); |
546 | } | 573 | } |
547 | if (penVert.width()>0) | 574 | if (penVert.width()>0) |
548 | { | 575 | { |
549 | p->setPen(penVert); | 576 | p->setPen(penVert); |
550 | p->drawLine(x+contentsRect().width()/2, lineFirstY, x+contentsRect().width()/2, lineLastY); | 577 | p->drawLine(x+contentsRect().width()/2, lineFirstY, x+contentsRect().width()/2, lineLastY); |
551 | } | 578 | } |
552 | } | 579 | } |
553 | 580 | ||
554 | void BorderEditor::setPen(const QPen &pen, BorderArea area) | 581 | void BorderEditor::setPen(const QPen &pen, BorderArea area) |
555 | { | 582 | { |
556 | switch (area) | 583 | switch (area) |
557 | { | 584 | { |
558 | case Top: penTop=pen; break; | 585 | case Top: penTop=pen; break; |
559 | case Bottom: penBottom=pen; break; | 586 | case Bottom: penBottom=pen; break; |
560 | case Left: penLeft=pen; break; | 587 | case Left: penLeft=pen; break; |
561 | case Right: penRight=pen; break; | 588 | case Right: penRight=pen; break; |
562 | case Horz: penHorz=pen; break; | 589 | case Horz: penHorz=pen; break; |
563 | case Vert: penVert=pen; break; | 590 | case Vert: penVert=pen; break; |
564 | }; | 591 | }; |
565 | update(); | 592 | update(); |
566 | } | 593 | } |
567 | 594 | ||
568 | void BorderEditor::mouseReleaseEvent(QMouseEvent *e) | 595 | void BorderEditor::mouseReleaseEvent(QMouseEvent *e) |
569 | { | 596 | { |
570 | QFrame::mouseReleaseEvent(e); | 597 | QFrame::mouseReleaseEvent(e); |
571 | 598 | ||
572 | int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3; | 599 | int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3; |
573 | BorderArea area=None; | 600 | BorderArea area=None; |
574 | 601 | ||
575 | if (e->x()<x+width/3) area=Left; | 602 | if (e->x()<x+width/3) area=Left; |
576 | if (e->x()>x+(8*width)/3) area=Right; | 603 | if (e->x()>x+(8*width)/3) area=Right; |
577 | if (e->x()>x+(4*width)/3 && e->x()<x+(5*width)/3) area=Vert; | 604 | if (e->x()>x+(4*width)/3 && e->x()<x+(5*width)/3) area=Vert; |
578 | 605 | ||
579 | if (e->y()<y+height/3) area=Top; | 606 | if (e->y()<y+height/3) area=Top; |
580 | if (e->y()>y+(8*height)/3) area=Bottom; | 607 | if (e->y()>y+(8*height)/3) area=Bottom; |
581 | if (e->y()>y+(4*height)/3 && e->y()<y+(5*height)/3) area=Horz; | 608 | if (e->y()>y+(4*height)/3 && e->y()<y+(5*height)/3) area=Horz; |
582 | 609 | ||
583 | if (area!=None) | 610 | if (area!=None) |
584 | emit clicked(area); | 611 | emit clicked(area); |
585 | } | 612 | } |
586 | 613 | ||
587 | QPen BorderEditor::getPen(BorderArea area) | 614 | QPen BorderEditor::getPen(BorderArea area) |
588 | { | 615 | { |
589 | switch (area) | 616 | switch (area) |
590 | { | 617 | { |
591 | case Top: return penTop; | 618 | case Top: return penTop; |
592 | case Bottom: return penBottom; | 619 | case Bottom: return penBottom; |
593 | case Left: return penLeft; | 620 | case Left: return penLeft; |
594 | case Right: return penRight; | 621 | case Right: return penRight; |
595 | case Horz: return penHorz; | 622 | case Horz: return penHorz; |
596 | case Vert: return penVert; | 623 | case Vert: return penVert; |
597 | }; | 624 | }; |
598 | return getDefaultPen(); | 625 | return getDefaultPen(); |
599 | } | 626 | } |
diff --git a/noncore/apps/opie-sheet/finddlg.cpp b/noncore/apps/opie-sheet/finddlg.cpp index d1237ca..e4c6ec8 100644 --- a/noncore/apps/opie-sheet/finddlg.cpp +++ b/noncore/apps/opie-sheet/finddlg.cpp | |||
@@ -1,84 +1,84 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | /* | 10 | /* |
11 | * Opie Sheet (formerly Sheet/Qt) | 11 | * Opie Sheet (formerly Sheet/Qt) |
12 | * by Serdar Ozler <sozler@sitebest.com> | 12 | * by Serdar Ozler <sozler@sitebest.com> |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <qlabel.h> | 15 | #include <qlabel.h> |
16 | #include <qradiobutton.h> | 16 | #include <qradiobutton.h> |
17 | #include "finddlg.h" | 17 | #include "finddlg.h" |
18 | 18 | ||
19 | FindDialog::FindDialog(QWidget *parent=0) | 19 | FindDialog::FindDialog(QWidget *parent) |
20 | :QDialog(parent, 0, TRUE) | 20 | :QDialog(parent, 0, TRUE) |
21 | { | 21 | { |
22 | // Main widget | 22 | // Main widget |
23 | tabs=new QTabWidget(this); | 23 | tabs=new QTabWidget(this); |
24 | widgetFind=new QWidget(tabs); | 24 | widgetFind=new QWidget(tabs); |
25 | widgetOptions=new QWidget(tabs); | 25 | widgetOptions=new QWidget(tabs); |
26 | tabs->addTab(widgetFind, tr("&Find && Replace")); | 26 | tabs->addTab(widgetFind, tr("&Find && Replace")); |
27 | tabs->addTab(widgetOptions, tr("&Options")); | 27 | tabs->addTab(widgetOptions, tr("&Options")); |
28 | 28 | ||
29 | // Find tab | 29 | // Find tab |
30 | QLabel *label=new QLabel(tr("&Search for:"), widgetFind); | 30 | QLabel *label=new QLabel(tr("&Search for:"), widgetFind); |
31 | label->setGeometry(10, 10, 215, 20); | 31 | label->setGeometry(10, 10, 215, 20); |
32 | editFind=new QLineEdit(widgetFind); | 32 | editFind=new QLineEdit(widgetFind); |
33 | editFind->setGeometry(10, 40, 215, 20); | 33 | editFind->setGeometry(10, 40, 215, 20); |
34 | label->setBuddy(editFind); | 34 | label->setBuddy(editFind); |
35 | 35 | ||
36 | label=new QLabel(tr("&Replace with:"), widgetFind); | 36 | label=new QLabel(tr("&Replace with:"), widgetFind); |
37 | label->setGeometry(10, 80, 215, 20); | 37 | label->setGeometry(10, 80, 215, 20); |
38 | editReplace=new QLineEdit(widgetFind); | 38 | editReplace=new QLineEdit(widgetFind); |
39 | editReplace->setGeometry(10, 110, 215, 20); | 39 | editReplace->setGeometry(10, 110, 215, 20); |
40 | editReplace->setEnabled(FALSE); | 40 | editReplace->setEnabled(FALSE); |
41 | label->setBuddy(editReplace); | 41 | label->setBuddy(editReplace); |
42 | 42 | ||
43 | groupType=new QVButtonGroup(tr("&Type"), widgetFind); | 43 | groupType=new QVButtonGroup(tr("&Type"), widgetFind); |
44 | groupType->setGeometry(10, 150, 215, 90); | 44 | groupType->setGeometry(10, 150, 215, 90); |
45 | QRadioButton *radio=new QRadioButton(tr("&Find"), groupType); | 45 | QRadioButton *radio=new QRadioButton(tr("&Find"), groupType); |
46 | radio=new QRadioButton(tr("&Replace"), groupType); | 46 | radio=new QRadioButton(tr("&Replace"), groupType); |
47 | radio=new QRadioButton(tr("Replace &all"), groupType); | 47 | radio=new QRadioButton(tr("Replace &all"), groupType); |
48 | groupType->setButton(0); | 48 | groupType->setButton(0); |
49 | connect(groupType, SIGNAL(clicked(int)), this, SLOT(typeChanged(int))); | 49 | connect(groupType, SIGNAL(clicked(int)), this, SLOT(typeChanged(int))); |
50 | 50 | ||
51 | // Options tab | 51 | // Options tab |
52 | checkCase=new QCheckBox(tr("Match &case"), widgetOptions); | 52 | checkCase=new QCheckBox(tr("Match &case"), widgetOptions); |
53 | checkCase->setGeometry(10, 10, 215, 20); | 53 | checkCase->setGeometry(10, 10, 215, 20); |
54 | checkSelection=new QCheckBox(tr("Current &selection only"), widgetOptions); | 54 | checkSelection=new QCheckBox(tr("Current &selection only"), widgetOptions); |
55 | checkSelection->setGeometry(10, 40, 215, 20); | 55 | checkSelection->setGeometry(10, 40, 215, 20); |
56 | checkEntire=new QCheckBox(tr("&Entire cell"), widgetOptions); | 56 | checkEntire=new QCheckBox(tr("&Entire cell"), widgetOptions); |
57 | checkEntire->setGeometry(10, 70, 215, 20); | 57 | checkEntire->setGeometry(10, 70, 215, 20); |
58 | 58 | ||
59 | // Main widget | 59 | // Main widget |
60 | box=new QVBoxLayout(this); | 60 | box=new QVBoxLayout(this); |
61 | box->addWidget(tabs); | 61 | box->addWidget(tabs); |
62 | 62 | ||
63 | setCaption(tr("Find & Replace")); | 63 | setCaption(tr("Find & Replace")); |
64 | } | 64 | } |
65 | 65 | ||
66 | FindDialog::~FindDialog() | 66 | FindDialog::~FindDialog() |
67 | { | 67 | { |
68 | } | 68 | } |
69 | 69 | ||
70 | void FindDialog::typeChanged(int id) | 70 | void FindDialog::typeChanged(int id) |
71 | { | 71 | { |
72 | editReplace->setEnabled(id>0); | 72 | editReplace->setEnabled(id>0); |
73 | } | 73 | } |
74 | 74 | ||
75 | int FindDialog::exec(Sheet *s) | 75 | int FindDialog::exec(Sheet *s) |
76 | { | 76 | { |
77 | if (QDialog::exec()==QDialog::Accepted) | 77 | if (QDialog::exec()==QDialog::Accepted) |
78 | { | 78 | { |
79 | int id=groupType->id(groupType->selected()); | 79 | int id=groupType->id(groupType->selected()); |
80 | s->dataFindReplace(editFind->text(), editReplace->text(), checkCase->isChecked(), !checkSelection->isChecked(), checkEntire->isChecked(), id>0, id>1); | 80 | s->dataFindReplace(editFind->text(), editReplace->text(), checkCase->isChecked(), !checkSelection->isChecked(), checkEntire->isChecked(), id>0, id>1); |
81 | return QDialog::Accepted; | 81 | return QDialog::Accepted; |
82 | } | 82 | } |
83 | return QDialog::Rejected; | 83 | return QDialog::Rejected; |
84 | } | 84 | } |
diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp index 09ee68b..2f07bae 100644 --- a/noncore/apps/opie-sheet/mainwindow.cpp +++ b/noncore/apps/opie-sheet/mainwindow.cpp | |||
@@ -41,257 +41,257 @@ | |||
41 | #include "func-func.xpm" | 41 | #include "func-func.xpm" |
42 | #include "func-equal.xpm" | 42 | #include "func-equal.xpm" |
43 | #include "cell-select.xpm" | 43 | #include "cell-select.xpm" |
44 | 44 | ||
45 | #define DEFAULT_NUM_ROWS 199 | 45 | #define DEFAULT_NUM_ROWS 199 |
46 | #define DEFAULT_NUM_COLS (26*3) | 46 | #define DEFAULT_NUM_COLS (26*3) |
47 | #define DEFAULT_NUM_SHEETS 3 | 47 | #define DEFAULT_NUM_SHEETS 3 |
48 | 48 | ||
49 | MainWindow::MainWindow() | 49 | MainWindow::MainWindow() |
50 | :QMainWindow() | 50 | :QMainWindow() |
51 | { | 51 | { |
52 | // initialize variables | 52 | // initialize variables |
53 | documentModified=FALSE; | 53 | documentModified=FALSE; |
54 | 54 | ||
55 | // construct objects | 55 | // construct objects |
56 | currentDoc=0; | 56 | currentDoc=0; |
57 | fileSelector=new FileSelector("application/sheet-qt", this, QString::null); | 57 | fileSelector=new FileSelector("application/sheet-qt", this, QString::null); |
58 | connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide())); | 58 | connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide())); |
59 | connect(fileSelector, SIGNAL(newSelected(const DocLnk &)), this, SLOT(selectorFileNew(const DocLnk &))); | 59 | connect(fileSelector, SIGNAL(newSelected(const DocLnk &)), this, SLOT(selectorFileNew(const DocLnk &))); |
60 | connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(selectorFileOpen(const DocLnk &))); | 60 | connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(selectorFileOpen(const DocLnk &))); |
61 | 61 | ||
62 | listSheets.setAutoDelete(TRUE); | 62 | listSheets.setAutoDelete(TRUE); |
63 | 63 | ||
64 | initActions(); | 64 | initActions(); |
65 | initMenu(); | 65 | initMenu(); |
66 | initEditToolbar(); | 66 | initEditToolbar(); |
67 | initFunctionsToolbar(); | 67 | initFunctionsToolbar(); |
68 | initStandardToolbar(); | 68 | initStandardToolbar(); |
69 | initSheet(); | 69 | initSheet(); |
70 | 70 | ||
71 | // set window title | 71 | // set window title |
72 | setCaption(tr("Opie Sheet")); | 72 | setCaption(tr("Opie Sheet")); |
73 | 73 | ||
74 | // create sheets | 74 | // create sheets |
75 | selectorFileNew(DocLnk()); | 75 | selectorFileNew(DocLnk()); |
76 | } | 76 | } |
77 | 77 | ||
78 | MainWindow::~MainWindow() | 78 | MainWindow::~MainWindow() |
79 | { | 79 | { |
80 | if (currentDoc) delete currentDoc; | 80 | if (currentDoc) delete currentDoc; |
81 | } | 81 | } |
82 | 82 | ||
83 | void MainWindow::documentSave(DocLnk *lnkDoc) | 83 | void MainWindow::documentSave(DocLnk *lnkDoc) |
84 | { | 84 | { |
85 | FileManager fm; | 85 | FileManager fm; |
86 | QByteArray streamBuffer; | 86 | QByteArray streamBuffer; |
87 | QDataStream stream(streamBuffer, IO_WriteOnly); | 87 | QDataStream stream(streamBuffer, IO_WriteOnly); |
88 | 88 | ||
89 | typeSheet *currentSheet=findSheet(sheet->getName()); | 89 | typeSheet *currentSheet=findSheet(sheet->getName()); |
90 | if (!currentSheet) | 90 | if (!currentSheet) |
91 | { | 91 | { |
92 | QMessageBox::critical(this, tr("Error"), tr("Inconsistency error!")); | 92 | QMessageBox::critical(this, tr("Error"), tr("Inconsistency error!")); |
93 | return; | 93 | return; |
94 | } | 94 | } |
95 | sheet->copySheetData(¤tSheet->data); | 95 | sheet->copySheetData(¤tSheet->data); |
96 | stream.writeRawBytes("SQT100", 6); | 96 | stream.writeRawBytes("SQT100", 6); |
97 | stream << (Q_UINT32)listSheets.count(); | 97 | stream << (Q_UINT32)listSheets.count(); |
98 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) | 98 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) |
99 | { | 99 | { |
100 | stream << tempSheet->name << (Q_UINT32)tempSheet->data.count(); | 100 | stream << tempSheet->name << (Q_UINT32)tempSheet->data.count(); |
101 | for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next()) | 101 | for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next()) |
102 | stream << (Q_UINT32)tempCell->col << (Q_UINT32)tempCell->row << tempCell->borders.right << tempCell->borders.bottom << tempCell->background << (Q_UINT32)tempCell->alignment << tempCell->fontColor << tempCell->font << tempCell->data; | 102 | stream << (Q_UINT32)tempCell->col << (Q_UINT32)tempCell->row << tempCell->borders.right << tempCell->borders.bottom << tempCell->background << (Q_UINT32)tempCell->alignment << tempCell->fontColor << tempCell->font << tempCell->data; |
103 | } | 103 | } |
104 | 104 | ||
105 | lnkDoc->setType("application/sheet-qt"); | 105 | lnkDoc->setType("application/sheet-qt"); |
106 | if (!fm.saveFile(*lnkDoc, streamBuffer)) | 106 | if (!fm.saveFile(*lnkDoc, streamBuffer)) |
107 | { | 107 | { |
108 | QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!")); | 108 | QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!")); |
109 | return; | 109 | return; |
110 | } | 110 | } |
111 | documentModified=FALSE; | 111 | documentModified=FALSE; |
112 | } | 112 | } |
113 | 113 | ||
114 | void MainWindow::documentOpen(const DocLnk &lnkDoc) | 114 | void MainWindow::documentOpen(const DocLnk &lnkDoc) |
115 | { | 115 | { |
116 | FileManager fm; | 116 | FileManager fm; |
117 | QByteArray streamBuffer; | 117 | QByteArray streamBuffer; |
118 | if (!lnkDoc.isValid() || !fm.loadFile(lnkDoc, streamBuffer)) | 118 | if (!lnkDoc.isValid() || !fm.loadFile(lnkDoc, streamBuffer)) |
119 | { | 119 | { |
120 | QMessageBox::critical(this, tr("Error"), tr("File cannot be opened!")); | 120 | QMessageBox::critical(this, tr("Error"), tr("File cannot be opened!")); |
121 | documentModified=FALSE; | 121 | documentModified=FALSE; |
122 | selectorFileNew(DocLnk()); | 122 | selectorFileNew(DocLnk()); |
123 | return; | 123 | return; |
124 | } | 124 | } |
125 | QDataStream stream(streamBuffer, IO_ReadOnly); | 125 | QDataStream stream(streamBuffer, IO_ReadOnly); |
126 | 126 | ||
127 | Q_UINT32 countSheet, countCell, i, j, row, col, alignment; | 127 | Q_UINT32 countSheet, countCell, i, j, row, col, alignment; |
128 | typeSheet *newSheet; | 128 | typeSheet *newSheet; |
129 | typeCellData *newCell; | 129 | typeCellData *newCell; |
130 | 130 | ||
131 | char fileFormat[7]; | 131 | char fileFormat[7]; |
132 | stream.readRawBytes(fileFormat, 6); | 132 | stream.readRawBytes(fileFormat, 6); |
133 | fileFormat[6]=0; | 133 | fileFormat[6]=0; |
134 | if ((QString)fileFormat!="SQT100") | 134 | if ((QString)fileFormat!="SQT100") |
135 | { | 135 | { |
136 | QMessageBox::critical(this, tr("Error"), tr("Invalid file format!")); | 136 | QMessageBox::critical(this, tr("Error"), tr("Invalid file format!")); |
137 | documentModified=FALSE; | 137 | documentModified=FALSE; |
138 | selectorFileNew(DocLnk()); | 138 | selectorFileNew(DocLnk()); |
139 | return; | 139 | return; |
140 | } | 140 | } |
141 | 141 | ||
142 | stream >> countSheet; | 142 | stream >> countSheet; |
143 | for (i=0; i<countSheet; ++i) | 143 | for (i=0; i<countSheet; ++i) |
144 | { | 144 | { |
145 | newSheet=new typeSheet; | 145 | newSheet=new typeSheet; |
146 | newSheet->data.setAutoDelete(TRUE); | 146 | newSheet->data.setAutoDelete(TRUE); |
147 | stream >> newSheet->name >> countCell; | 147 | stream >> newSheet->name >> countCell; |
148 | comboSheets->insertItem(newSheet->name); | 148 | comboSheets->insertItem(newSheet->name); |
149 | 149 | ||
150 | for (j=0; j<countCell; ++j) | 150 | for (j=0; j<countCell; ++j) |
151 | { | 151 | { |
152 | newCell=new typeCellData; | 152 | newCell=new typeCellData; |
153 | stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data; | 153 | stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data; |
154 | newCell->col=col; | 154 | newCell->col=col; |
155 | newCell->row=row; | 155 | newCell->row=row; |
156 | newCell->alignment=(Qt::AlignmentFlags)alignment; | 156 | newCell->alignment=(Qt::AlignmentFlags)alignment; |
157 | newSheet->data.append(newCell); | 157 | newSheet->data.append(newCell); |
158 | } | 158 | } |
159 | listSheets.append(newSheet); | 159 | listSheets.append(newSheet); |
160 | 160 | ||
161 | if (i==0) | 161 | if (i==0) |
162 | { | 162 | { |
163 | sheet->setName(newSheet->name); | 163 | sheet->setName(newSheet->name); |
164 | sheet->setSheetData(&newSheet->data); | 164 | sheet->setSheetData(&newSheet->data); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | } | 167 | } |
168 | 168 | ||
169 | int MainWindow::saveCurrentFile(bool ask=TRUE) | 169 | int MainWindow::saveCurrentFile(bool ask) |
170 | { | 170 | { |
171 | if (ask) | 171 | if (ask) |
172 | { | 172 | { |
173 | int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); | 173 | int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); |
174 | if (result!=QMessageBox::Yes) return result; | 174 | if (result!=QMessageBox::Yes) return result; |
175 | } | 175 | } |
176 | 176 | ||
177 | if (!currentDoc->isValid()) | 177 | if (!currentDoc->isValid()) |
178 | { | 178 | { |
179 | TextDialog dialogText(this); | 179 | TextDialog dialogText(this); |
180 | if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel; | 180 | if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel; |
181 | 181 | ||
182 | currentDoc->setName(dialogText.getValue()); | 182 | currentDoc->setName(dialogText.getValue()); |
183 | currentDoc->setFile(QString::null); | 183 | currentDoc->setFile(QString::null); |
184 | currentDoc->setLinkFile(QString::null); | 184 | currentDoc->setLinkFile(QString::null); |
185 | } | 185 | } |
186 | 186 | ||
187 | documentSave(currentDoc); | 187 | documentSave(currentDoc); |
188 | return QMessageBox::Yes; | 188 | return QMessageBox::Yes; |
189 | } | 189 | } |
190 | 190 | ||
191 | void MainWindow::selectorFileNew(const DocLnk &lnkDoc) | 191 | void MainWindow::selectorFileNew(const DocLnk &lnkDoc) |
192 | { | 192 | { |
193 | selectorHide(); | 193 | selectorHide(); |
194 | 194 | ||
195 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; | 195 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; |
196 | if (currentDoc) delete currentDoc; | 196 | if (currentDoc) delete currentDoc; |
197 | currentDoc = new DocLnk(lnkDoc); | 197 | currentDoc = new DocLnk(lnkDoc); |
198 | listSheets.clear(); | 198 | listSheets.clear(); |
199 | comboSheets->clear(); | 199 | comboSheets->clear(); |
200 | 200 | ||
201 | typeSheet *newSheet=createNewSheet(); | 201 | typeSheet *newSheet=createNewSheet(); |
202 | newSheet->data.setAutoDelete(TRUE); | 202 | newSheet->data.setAutoDelete(TRUE); |
203 | sheet->setName(newSheet->name); | 203 | sheet->setName(newSheet->name); |
204 | sheet->setSheetData(&newSheet->data); | 204 | sheet->setSheetData(&newSheet->data); |
205 | for (int i=1; i<DEFAULT_NUM_SHEETS; ++i) | 205 | for (int i=1; i<DEFAULT_NUM_SHEETS; ++i) |
206 | createNewSheet(); | 206 | createNewSheet(); |
207 | documentModified=FALSE; | 207 | documentModified=FALSE; |
208 | } | 208 | } |
209 | 209 | ||
210 | void MainWindow::closeEvent(QCloseEvent *e) | 210 | void MainWindow::closeEvent(QCloseEvent *e) |
211 | { | 211 | { |
212 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore(); | 212 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore(); |
213 | else e->accept(); | 213 | else e->accept(); |
214 | } | 214 | } |
215 | 215 | ||
216 | void MainWindow::selectorFileOpen(const DocLnk &lnkDoc) | 216 | void MainWindow::selectorFileOpen(const DocLnk &lnkDoc) |
217 | { | 217 | { |
218 | selectorHide(); | 218 | selectorHide(); |
219 | 219 | ||
220 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; | 220 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; |
221 | if (currentDoc) delete currentDoc; | 221 | if (currentDoc) delete currentDoc; |
222 | currentDoc = new DocLnk(lnkDoc); | 222 | currentDoc = new DocLnk(lnkDoc); |
223 | listSheets.clear(); | 223 | listSheets.clear(); |
224 | comboSheets->clear(); | 224 | comboSheets->clear(); |
225 | 225 | ||
226 | documentOpen(lnkDoc); | 226 | documentOpen(lnkDoc); |
227 | documentModified=FALSE; | 227 | documentModified=FALSE; |
228 | } | 228 | } |
229 | 229 | ||
230 | void MainWindow::selectorShow() | 230 | void MainWindow::selectorShow() |
231 | { | 231 | { |
232 | sheet->hide(); | 232 | sheet->hide(); |
233 | setCentralWidget(fileSelector); | 233 | setCentralWidget(fileSelector); |
234 | fileSelector->show(); | 234 | fileSelector->show(); |
235 | fileSelector->reread(); | 235 | fileSelector->reread(); |
236 | } | 236 | } |
237 | 237 | ||
238 | void MainWindow::selectorHide() | 238 | void MainWindow::selectorHide() |
239 | { | 239 | { |
240 | fileSelector->hide(); | 240 | fileSelector->hide(); |
241 | setCentralWidget(sheet); | 241 | setCentralWidget(sheet); |
242 | sheet->show(); | 242 | sheet->show(); |
243 | } | 243 | } |
244 | 244 | ||
245 | void MainWindow::slotFileNew() | 245 | void MainWindow::slotFileNew() |
246 | { | 246 | { |
247 | selectorFileNew(DocLnk()); | 247 | selectorFileNew(DocLnk()); |
248 | } | 248 | } |
249 | 249 | ||
250 | void MainWindow::slotFileOpen() | 250 | void MainWindow::slotFileOpen() |
251 | { | 251 | { |
252 | selectorShow(); | 252 | selectorShow(); |
253 | } | 253 | } |
254 | 254 | ||
255 | void MainWindow::slotFileSave() | 255 | void MainWindow::slotFileSave() |
256 | { | 256 | { |
257 | saveCurrentFile(FALSE); | 257 | saveCurrentFile(FALSE); |
258 | } | 258 | } |
259 | 259 | ||
260 | void MainWindow::setDocument(const QString &applnk_filename) | 260 | void MainWindow::setDocument(const QString &applnk_filename) |
261 | { | 261 | { |
262 | selectorFileOpen(DocLnk(applnk_filename)); | 262 | selectorFileOpen(DocLnk(applnk_filename)); |
263 | } | 263 | } |
264 | 264 | ||
265 | void MainWindow::initActions() | 265 | void MainWindow::initActions() |
266 | { | 266 | { |
267 | fileNew=new QAction(tr("New File"), QPixmap(file_new_xpm), tr("&New"), 0, this); | 267 | fileNew=new QAction(tr("New File"), QPixmap(file_new_xpm), tr("&New"), 0, this); |
268 | connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew())); | 268 | connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew())); |
269 | fileOpen=new QAction(tr("Open File"), QPixmap(file_open_xpm), tr("&Open"), 0, this); | 269 | fileOpen=new QAction(tr("Open File"), QPixmap(file_open_xpm), tr("&Open"), 0, this); |
270 | connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen())); | 270 | connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen())); |
271 | fileSave=new QAction(tr("Save File"), QPixmap(file_save_xpm), tr("&Save"), 0, this); | 271 | fileSave=new QAction(tr("Save File"), QPixmap(file_save_xpm), tr("&Save"), 0, this); |
272 | connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave())); | 272 | connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave())); |
273 | fileSaveAs=new QAction(tr("Save File As"), QPixmap(file_save_xpm), tr("Save &As"), 0, this); | 273 | fileSaveAs=new QAction(tr("Save File As"), QPixmap(file_save_xpm), tr("Save &As"), 0, this); |
274 | connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs())); | 274 | connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs())); |
275 | fileQuit=new QAction(tr("Quit"), tr("&Quit"), 0, this); | 275 | fileQuit=new QAction(tr("Quit"), tr("&Quit"), 0, this); |
276 | connect(fileQuit, SIGNAL(activated()), this, SLOT(close())); | 276 | connect(fileQuit, SIGNAL(activated()), this, SLOT(close())); |
277 | 277 | ||
278 | helpGeneral=new QAction(tr("General Help"), QPixmap(help_general_xpm), tr("&General"), 0, this); | 278 | helpGeneral=new QAction(tr("General Help"), QPixmap(help_general_xpm), tr("&General"), 0, this); |
279 | connect(helpGeneral, SIGNAL(activated()), this, SLOT(slotHelpGeneral())); | 279 | connect(helpGeneral, SIGNAL(activated()), this, SLOT(slotHelpGeneral())); |
280 | helpAbout=new QAction(tr("About Opie Sheet"), tr("&About"), 0, this); | 280 | helpAbout=new QAction(tr("About Opie Sheet"), tr("&About"), 0, this); |
281 | connect(helpAbout, SIGNAL(activated()), this, SLOT(slotHelpAbout())); | 281 | connect(helpAbout, SIGNAL(activated()), this, SLOT(slotHelpAbout())); |
282 | 282 | ||
283 | editAccept=new QAction(tr("Accept"), QPixmap(edit_accept_xpm), tr("&Accept"), 0, this); | 283 | editAccept=new QAction(tr("Accept"), QPixmap(edit_accept_xpm), tr("&Accept"), 0, this); |
284 | connect(editAccept, SIGNAL(activated()), this, SLOT(slotEditAccept())); | 284 | connect(editAccept, SIGNAL(activated()), this, SLOT(slotEditAccept())); |
285 | editCancel=new QAction(tr("Cancel"), QPixmap(edit_cancel_xpm), tr("&Cancel"), 0, this); | 285 | editCancel=new QAction(tr("Cancel"), QPixmap(edit_cancel_xpm), tr("&Cancel"), 0, this); |
286 | connect(editCancel, SIGNAL(activated()), this, SLOT(slotEditCancel())); | 286 | connect(editCancel, SIGNAL(activated()), this, SLOT(slotEditCancel())); |
287 | editCellSelect=new QAction(tr("Cell Selector"), QPixmap(cell_select_xpm), tr("Cell &Selector"), 0, this); | 287 | editCellSelect=new QAction(tr("Cell Selector"), QPixmap(cell_select_xpm), tr("Cell &Selector"), 0, this); |
288 | editCellSelect->setToggleAction(TRUE); | 288 | editCellSelect->setToggleAction(TRUE); |
289 | connect(editCellSelect, SIGNAL(toggled(bool)), this, SLOT(slotCellSelect(bool))); | 289 | connect(editCellSelect, SIGNAL(toggled(bool)), this, SLOT(slotCellSelect(bool))); |
290 | editCut=new QAction(tr("Cut Cells"), tr("Cu&t"), 0, this); | 290 | editCut=new QAction(tr("Cut Cells"), tr("Cu&t"), 0, this); |
291 | editCopy=new QAction(tr("Copy Cells"), tr("&Copy"), 0, this); | 291 | editCopy=new QAction(tr("Copy Cells"), tr("&Copy"), 0, this); |
292 | editPaste=new QAction(tr("Paste Cells"), tr("&Paste"), 0, this); | 292 | editPaste=new QAction(tr("Paste Cells"), tr("&Paste"), 0, this); |
293 | connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste())); | 293 | connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste())); |
294 | editPasteContents=new QAction(tr("Paste Contents"), tr("Paste Cont&ents"), 0, this); | 294 | editPasteContents=new QAction(tr("Paste Contents"), tr("Paste Cont&ents"), 0, this); |
295 | connect(editPasteContents, SIGNAL(activated()), this, SLOT(slotEditPasteContents())); | 295 | connect(editPasteContents, SIGNAL(activated()), this, SLOT(slotEditPasteContents())); |
296 | editClear=new QAction(tr("Clear Cells"), tr("C&lear"), 0, this); | 296 | editClear=new QAction(tr("Clear Cells"), tr("C&lear"), 0, this); |
297 | 297 | ||
diff --git a/noncore/apps/opie-sheet/numberdlg.cpp b/noncore/apps/opie-sheet/numberdlg.cpp index e8de639..90fbaa2 100644 --- a/noncore/apps/opie-sheet/numberdlg.cpp +++ b/noncore/apps/opie-sheet/numberdlg.cpp | |||
@@ -1,49 +1,50 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | /* | 10 | /* |
11 | * Opie Sheet (formerly Sheet/Qt) | 11 | * Opie Sheet (formerly Sheet/Qt) |
12 | * by Serdar Ozler <sozler@sitebest.com> | 12 | * by Serdar Ozler <sozler@sitebest.com> |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include "numberdlg.h" | 15 | #include "numberdlg.h" |
16 | 16 | ||
17 | NumberDialog::NumberDialog(QWidget *parent=0) | 17 | NumberDialog::NumberDialog(QWidget *parent) |
18 | :QDialog(parent, 0, TRUE) | 18 | :QDialog(parent, 0, TRUE) |
19 | { | 19 | { |
20 | edit=new QSpinBox(this); | 20 | edit=new QSpinBox(this); |
21 | edit->setGeometry(120, 10, 70, 25); | 21 | edit->setGeometry(120, 10, 70, 25); |
22 | 22 | ||
23 | label=new QLabel(this); | 23 | label=new QLabel(this); |
24 | label->setGeometry(10, 10, 100, 25); | 24 | label->setGeometry(10, 10, 100, 25); |
25 | label->setBuddy(edit); | 25 | label->setBuddy(edit); |
26 | 26 | ||
27 | resize(200, 45); | 27 | resize(200, 45); |
28 | } | 28 | } |
29 | 29 | ||
30 | NumberDialog::~NumberDialog() | 30 | NumberDialog::~NumberDialog() |
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | int NumberDialog::exec(const QString &caption, const QString &text, int value=1, int min=1, int max=99, int step=1) | 34 | int NumberDialog::exec(const QString &caption, const QString &text, |
35 | int value, int min, int max, int step) | ||
35 | { | 36 | { |
36 | setCaption(caption); | 37 | setCaption(caption); |
37 | label->setText(text); | 38 | label->setText(text); |
38 | edit->setValue(value); | 39 | edit->setValue(value); |
39 | edit->setMinValue(min); | 40 | edit->setMinValue(min); |
40 | edit->setMaxValue(max); | 41 | edit->setMaxValue(max); |
41 | edit->setLineStep(step); | 42 | edit->setLineStep(step); |
42 | 43 | ||
43 | return QDialog::exec(); | 44 | return QDialog::exec(); |
44 | } | 45 | } |
45 | 46 | ||
46 | int NumberDialog::getValue() | 47 | int NumberDialog::getValue() |
47 | { | 48 | { |
48 | return edit->value(); | 49 | return edit->value(); |
49 | } | 50 | } |
diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp index 1d7ec6f..2279191 100644 --- a/noncore/apps/opie-sheet/sheet.cpp +++ b/noncore/apps/opie-sheet/sheet.cpp | |||
@@ -1,276 +1,276 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | /* | 10 | /* |
11 | * Opie Sheet (formerly Sheet/Qt) | 11 | * Opie Sheet (formerly Sheet/Qt) |
12 | * by Serdar Ozler <sozler@sitebest.com> | 12 | * by Serdar Ozler <sozler@sitebest.com> |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include "sheet.h" | 15 | #include "sheet.h" |
16 | 16 | ||
17 | #include <qmainwindow.h> | 17 | #include <qmainwindow.h> |
18 | #include <qmessagebox.h> | 18 | #include <qmessagebox.h> |
19 | #include <math.h> | 19 | #include <math.h> |
20 | 20 | ||
21 | #define DEFAULT_COL_WIDTH 50 | 21 | #define DEFAULT_COL_WIDTH 50 |
22 | 22 | ||
23 | Sheet::Sheet(int numRows, int numCols, QWidget *parent) | 23 | Sheet::Sheet(int numRows, int numCols, QWidget *parent) |
24 | :QTable(numRows, numCols, parent) | 24 | :QTable(numRows, numCols, parent) |
25 | { | 25 | { |
26 | defaultBorders.right=defaultBorders.bottom=QPen(Qt::gray, 1, Qt::SolidLine); | 26 | defaultBorders.right=defaultBorders.bottom=QPen(Qt::gray, 1, Qt::SolidLine); |
27 | defaultCellData.data=""; | 27 | defaultCellData.data=""; |
28 | defaultCellData.background=QBrush(Qt::white, Qt::SolidPattern); | 28 | defaultCellData.background=QBrush(Qt::white, Qt::SolidPattern); |
29 | defaultCellData.alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop); | 29 | defaultCellData.alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop); |
30 | defaultCellData.fontColor=Qt::black; | 30 | defaultCellData.fontColor=Qt::black; |
31 | defaultCellData.font=font(); | 31 | defaultCellData.font=font(); |
32 | defaultCellData.borders=defaultBorders; | 32 | defaultCellData.borders=defaultBorders; |
33 | 33 | ||
34 | selectionNo=-1; | 34 | selectionNo=-1; |
35 | setSelectionMode(QTable::Single); | 35 | setSelectionMode(QTable::Single); |
36 | 36 | ||
37 | sheetData.setAutoDelete(TRUE); | 37 | sheetData.setAutoDelete(TRUE); |
38 | clipboardData.setAutoDelete(TRUE); | 38 | clipboardData.setAutoDelete(TRUE); |
39 | for (int i=0; i<numCols; ++i) | 39 | for (int i=0; i<numCols; ++i) |
40 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); | 40 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); |
41 | 41 | ||
42 | connect(this, SIGNAL(currentChanged(int, int)), this, SLOT(slotCellSelected(int, int))); | 42 | connect(this, SIGNAL(currentChanged(int, int)), this, SLOT(slotCellSelected(int, int))); |
43 | connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(slotCellChanged(int, int))); | 43 | connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(slotCellChanged(int, int))); |
44 | } | 44 | } |
45 | 45 | ||
46 | Sheet::~Sheet() | 46 | Sheet::~Sheet() |
47 | { | 47 | { |
48 | } | 48 | } |
49 | 49 | ||
50 | typeCellData *Sheet::findCellData(int row, int col) | 50 | typeCellData *Sheet::findCellData(int row, int col) |
51 | { | 51 | { |
52 | typeCellData *tempCellData; | 52 | typeCellData *tempCellData; |
53 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 53 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
54 | if (tempCellData->row==row && tempCellData->col==col) | 54 | if (tempCellData->row==row && tempCellData->col==col) |
55 | return tempCellData; | 55 | return tempCellData; |
56 | return NULL; | 56 | return NULL; |
57 | } | 57 | } |
58 | 58 | ||
59 | void Sheet::slotCellSelected(int row, int col) | 59 | void Sheet::slotCellSelected(int row, int col) |
60 | { | 60 | { |
61 | typeCellData *cellData=findCellData(row, col); | 61 | typeCellData *cellData=findCellData(row, col); |
62 | if (cellData) | 62 | if (cellData) |
63 | emit currentDataChanged(cellData->data); | 63 | emit currentDataChanged(cellData->data); |
64 | else | 64 | else |
65 | emit currentDataChanged(""); | 65 | emit currentDataChanged(""); |
66 | } | 66 | } |
67 | 67 | ||
68 | typeCellData *Sheet::createCellData(int row, int col) | 68 | typeCellData *Sheet::createCellData(int row, int col) |
69 | { | 69 | { |
70 | if (row<0 || col<0) return NULL; | 70 | if (row<0 || col<0) return NULL; |
71 | typeCellData *cellData=new typeCellData; | 71 | typeCellData *cellData=new typeCellData; |
72 | cellData->row=row; | 72 | cellData->row=row; |
73 | cellData->col=col; | 73 | cellData->col=col; |
74 | cellData->data=defaultCellData.data; | 74 | cellData->data=defaultCellData.data; |
75 | cellData->borders=defaultCellData.borders; | 75 | cellData->borders=defaultCellData.borders; |
76 | cellData->alignment=defaultCellData.alignment; | 76 | cellData->alignment=defaultCellData.alignment; |
77 | cellData->font=defaultCellData.font; | 77 | cellData->font=defaultCellData.font; |
78 | cellData->fontColor=defaultCellData.fontColor; | 78 | cellData->fontColor=defaultCellData.fontColor; |
79 | cellData->background=defaultCellData.background; | 79 | cellData->background=defaultCellData.background; |
80 | sheetData.append(cellData); | 80 | sheetData.append(cellData); |
81 | return cellData; | 81 | return cellData; |
82 | } | 82 | } |
83 | 83 | ||
84 | void Sheet::slotCellChanged(int row, int col) | 84 | void Sheet::slotCellChanged(int row, int col) |
85 | { | 85 | { |
86 | typeCellData *cellData=findCellData(row, col); | 86 | typeCellData *cellData=findCellData(row, col); |
87 | if (!cellData) cellData=createCellData(row, col); | 87 | if (!cellData) cellData=createCellData(row, col); |
88 | if (cellData) cellData->data=text(row, col); | 88 | if (cellData) cellData->data=text(row, col); |
89 | for (cellData=sheetData.first(); cellData; cellData=sheetData.next()) | 89 | for (cellData=sheetData.first(); cellData; cellData=sheetData.next()) |
90 | setText(cellData->row, cellData->col, dataParser(cellData->data)); | 90 | setText(cellData->row, cellData->col, dataParser(cellData->data)); |
91 | emit sheetModified(); | 91 | emit sheetModified(); |
92 | } | 92 | } |
93 | 93 | ||
94 | void Sheet::swapCells(int row1, int col1, int row2, int col2) | 94 | void Sheet::swapCells(int row1, int col1, int row2, int col2) |
95 | { | 95 | { |
96 | typeCellData *cellData1=findCellData(row1, col1), *cellData2=findCellData(row2, col2); | 96 | typeCellData *cellData1=findCellData(row1, col1), *cellData2=findCellData(row2, col2); |
97 | if (!cellData1) cellData1=createCellData(row1, col1); | 97 | if (!cellData1) cellData1=createCellData(row1, col1); |
98 | if (!cellData2) cellData2=createCellData(row2, col2); | 98 | if (!cellData2) cellData2=createCellData(row2, col2); |
99 | if (cellData1 && cellData2) | 99 | if (cellData1 && cellData2) |
100 | { | 100 | { |
101 | QString tempData(cellData1->data); | 101 | QString tempData(cellData1->data); |
102 | cellData1->data=cellData2->data; | 102 | cellData1->data=cellData2->data; |
103 | cellData2->data=tempData; | 103 | cellData2->data=tempData; |
104 | setText(cellData1->row, cellData1->col, dataParser(cellData1->data)); | 104 | setText(cellData1->row, cellData1->col, dataParser(cellData1->data)); |
105 | setText(cellData2->row, cellData2->col, dataParser(cellData2->data)); | 105 | setText(cellData2->row, cellData2->col, dataParser(cellData2->data)); |
106 | emit sheetModified(); | 106 | emit sheetModified(); |
107 | } | 107 | } |
108 | } | 108 | } |
109 | 109 | ||
110 | QString Sheet::getParameter(const QString ¶meters, int paramNo, bool giveError=FALSE, const QString funcName="") | 110 | QString Sheet::getParameter(const QString ¶meters, int paramNo, bool giveError, const QString funcName) |
111 | { | 111 | { |
112 | QString params(parameters); | 112 | QString params(parameters); |
113 | int position; | 113 | int position; |
114 | for (int i=0; i<paramNo; ++i) | 114 | for (int i=0; i<paramNo; ++i) |
115 | { | 115 | { |
116 | position=params.find(','); | 116 | position=params.find(','); |
117 | if (position<0) | 117 | if (position<0) |
118 | { | 118 | { |
119 | if (giveError) QMessageBox::critical(this, tr("Error"), tr("Too few arguments to function '"+funcName+'\'')); | 119 | if (giveError) QMessageBox::critical(this, tr("Error"), tr("Too few arguments to function '"+funcName+'\'')); |
120 | return QString(); | 120 | return QString(); |
121 | } | 121 | } |
122 | params=params.mid(position+1); | 122 | params=params.mid(position+1); |
123 | } | 123 | } |
124 | position=params.find(','); | 124 | position=params.find(','); |
125 | if (position<0) return params; | 125 | if (position<0) return params; |
126 | return params.left(position); | 126 | return params.left(position); |
127 | } | 127 | } |
128 | 128 | ||
129 | bool Sheet::findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2) | 129 | bool Sheet::findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2) |
130 | { | 130 | { |
131 | int row, col; | 131 | int row, col; |
132 | if (!findRowColumn(variable1, row1, col1, TRUE) || !findRowColumn(variable2, row2, col2, TRUE)) return FALSE; | 132 | if (!findRowColumn(variable1, row1, col1, TRUE) || !findRowColumn(variable2, row2, col2, TRUE)) return FALSE; |
133 | if (*row1>*row2) | 133 | if (*row1>*row2) |
134 | { | 134 | { |
135 | row=*row1; | 135 | row=*row1; |
136 | *row1=*row2; | 136 | *row1=*row2; |
137 | *row2=row; | 137 | *row2=row; |
138 | } | 138 | } |
139 | if (*col1>*col2) | 139 | if (*col1>*col2) |
140 | { | 140 | { |
141 | col=*col1; | 141 | col=*col1; |
142 | *col1=*col2; | 142 | *col1=*col2; |
143 | *col2=col; | 143 | *col2=col; |
144 | } | 144 | } |
145 | return TRUE; | 145 | return TRUE; |
146 | } | 146 | } |
147 | 147 | ||
148 | bool Sheet::findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE) | 148 | bool Sheet::findRowColumn(const QString &variable, int *row, int *col, bool giveError) |
149 | { | 149 | { |
150 | int position=variable.find(QRegExp("\\d")); | 150 | int position=variable.find(QRegExp("\\d")); |
151 | if (position<1) | 151 | if (position<1) |
152 | { | 152 | { |
153 | if (giveError) QMessageBox::critical(this, tr("Error"), tr("Invalid variable: '"+variable+'\'')); | 153 | if (giveError) QMessageBox::critical(this, tr("Error"), tr("Invalid variable: '"+variable+'\'')); |
154 | return FALSE; | 154 | return FALSE; |
155 | } | 155 | } |
156 | *row=variable.mid(position).toInt()-1; | 156 | *row=variable.mid(position).toInt()-1; |
157 | *col=getHeaderColumn(variable.left(position))-1; | 157 | *col=getHeaderColumn(variable.left(position))-1; |
158 | return TRUE; | 158 | return TRUE; |
159 | } | 159 | } |
160 | 160 | ||
161 | double Sheet::calculateVariable(const QString &variable) | 161 | double Sheet::calculateVariable(const QString &variable) |
162 | { | 162 | { |
163 | bool ok; | 163 | bool ok; |
164 | double tempResult=variable.toDouble(&ok); | 164 | double tempResult=variable.toDouble(&ok); |
165 | if (ok) return tempResult; | 165 | if (ok) return tempResult; |
166 | 166 | ||
167 | int row, col; | 167 | int row, col; |
168 | return (findRowColumn(variable, &row, &col, TRUE) ? text(row, col).toDouble() : 0); | 168 | return (findRowColumn(variable, &row, &col, TRUE) ? text(row, col).toDouble() : 0); |
169 | } | 169 | } |
170 | 170 | ||
171 | double Sheet::functionSum(const QString ¶m1, const QString ¶m2) | 171 | double Sheet::functionSum(const QString ¶m1, const QString ¶m2) |
172 | { | 172 | { |
173 | int row1, col1, row2, col2, row, col; | 173 | int row1, col1, row2, col2, row, col; |
174 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 174 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
175 | 175 | ||
176 | double result=0, tempResult; | 176 | double result=0, tempResult; |
177 | bool ok; | 177 | bool ok; |
178 | for (row=row1; row<=row2; ++row) | 178 | for (row=row1; row<=row2; ++row) |
179 | for (col=col1; col<=col2; ++col) | 179 | for (col=col1; col<=col2; ++col) |
180 | { | 180 | { |
181 | tempResult=text(row, col).toDouble(&ok); | 181 | tempResult=text(row, col).toDouble(&ok); |
182 | if (ok) result+=tempResult; | 182 | if (ok) result+=tempResult; |
183 | } | 183 | } |
184 | 184 | ||
185 | return result; | 185 | return result; |
186 | } | 186 | } |
187 | 187 | ||
188 | double Sheet::functionMin(const QString ¶m1, const QString ¶m2) | 188 | double Sheet::functionMin(const QString ¶m1, const QString ¶m2) |
189 | { | 189 | { |
190 | int row1, col1, row2, col2, row, col; | 190 | int row1, col1, row2, col2, row, col; |
191 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 191 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
192 | 192 | ||
193 | double min=0, tempMin; | 193 | double min=0, tempMin; |
194 | bool ok, init=FALSE; | 194 | bool ok, init=FALSE; |
195 | for (row=row1; row<=row2; ++row) | 195 | for (row=row1; row<=row2; ++row) |
196 | for (col=col1; col<=col2; ++col) | 196 | for (col=col1; col<=col2; ++col) |
197 | { | 197 | { |
198 | tempMin=text(row, col).toDouble(&ok); | 198 | tempMin=text(row, col).toDouble(&ok); |
199 | if (ok && (!init || tempMin<min)) | 199 | if (ok && (!init || tempMin<min)) |
200 | { | 200 | { |
201 | min=tempMin; | 201 | min=tempMin; |
202 | init=TRUE; | 202 | init=TRUE; |
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
206 | return min; | 206 | return min; |
207 | } | 207 | } |
208 | 208 | ||
209 | double Sheet::functionMax(const QString ¶m1, const QString ¶m2) | 209 | double Sheet::functionMax(const QString ¶m1, const QString ¶m2) |
210 | { | 210 | { |
211 | int row1, col1, row2, col2, row, col; | 211 | int row1, col1, row2, col2, row, col; |
212 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 212 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
213 | 213 | ||
214 | double max=0, tempMax; | 214 | double max=0, tempMax; |
215 | bool ok, init=FALSE; | 215 | bool ok, init=FALSE; |
216 | for (row=row1; row<=row2; ++row) | 216 | for (row=row1; row<=row2; ++row) |
217 | for (col=col1; col<=col2; ++col) | 217 | for (col=col1; col<=col2; ++col) |
218 | { | 218 | { |
219 | tempMax=text(row, col).toDouble(&ok); | 219 | tempMax=text(row, col).toDouble(&ok); |
220 | if (ok && (!init || tempMax>max)) | 220 | if (ok && (!init || tempMax>max)) |
221 | { | 221 | { |
222 | max=tempMax; | 222 | max=tempMax; |
223 | init=TRUE; | 223 | init=TRUE; |
224 | } | 224 | } |
225 | } | 225 | } |
226 | 226 | ||
227 | return max; | 227 | return max; |
228 | } | 228 | } |
229 | 229 | ||
230 | double Sheet::functionAvg(const QString ¶m1, const QString ¶m2) | 230 | double Sheet::functionAvg(const QString ¶m1, const QString ¶m2) |
231 | { | 231 | { |
232 | double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2); | 232 | double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2); |
233 | return (resultCount>0 ? resultSum/resultCount : 0); | 233 | return (resultCount>0 ? resultSum/resultCount : 0); |
234 | } | 234 | } |
235 | 235 | ||
236 | double Sheet::functionCount(const QString ¶m1, const QString ¶m2) | 236 | double Sheet::functionCount(const QString ¶m1, const QString ¶m2) |
237 | { | 237 | { |
238 | int row1, col1, row2, col2, row, col; | 238 | int row1, col1, row2, col2, row, col; |
239 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 239 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
240 | 240 | ||
241 | int divider=0; | 241 | int divider=0; |
242 | bool ok; | 242 | bool ok; |
243 | for (row=row1; row<=row2; ++row) | 243 | for (row=row1; row<=row2; ++row) |
244 | for (col=col1; col<=col2; ++col) | 244 | for (col=col1; col<=col2; ++col) |
245 | { | 245 | { |
246 | text(row, col).toDouble(&ok); | 246 | text(row, col).toDouble(&ok); |
247 | if (ok) ++divider; | 247 | if (ok) ++divider; |
248 | } | 248 | } |
249 | 249 | ||
250 | return divider; | 250 | return divider; |
251 | } | 251 | } |
252 | 252 | ||
253 | double Sheet::calculateFunction(const QString &function, const QString ¶meters) | 253 | double Sheet::calculateFunction(const QString &function, const QString ¶meters) |
254 | { | 254 | { |
255 | if (function=="+") | 255 | if (function=="+") |
256 | return calculateVariable(getParameter(parameters, 0))+calculateVariable(getParameter(parameters, 1)); | 256 | return calculateVariable(getParameter(parameters, 0))+calculateVariable(getParameter(parameters, 1)); |
257 | if (function=="-") | 257 | if (function=="-") |
258 | return calculateVariable(getParameter(parameters, 0))-calculateVariable(getParameter(parameters, 1)); | 258 | return calculateVariable(getParameter(parameters, 0))-calculateVariable(getParameter(parameters, 1)); |
259 | if (function=="*") | 259 | if (function=="*") |
260 | return calculateVariable(getParameter(parameters, 0))*calculateVariable(getParameter(parameters, 1)); | 260 | return calculateVariable(getParameter(parameters, 0))*calculateVariable(getParameter(parameters, 1)); |
261 | if (function=="/") | 261 | if (function=="/") |
262 | return calculateVariable(getParameter(parameters, 0))/calculateVariable(getParameter(parameters, 1)); | 262 | return calculateVariable(getParameter(parameters, 0))/calculateVariable(getParameter(parameters, 1)); |
263 | if (function=="SUM") | 263 | if (function=="SUM") |
264 | return functionSum(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 264 | return functionSum(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
265 | if (function=="COUNT") | 265 | if (function=="COUNT") |
266 | return functionCount(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 266 | return functionCount(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
267 | if (function=="MIN") | 267 | if (function=="MIN") |
268 | return functionMin(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 268 | return functionMin(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
269 | if (function=="MAX") | 269 | if (function=="MAX") |
270 | return functionMax(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 270 | return functionMax(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
271 | if (function=="AVG") | 271 | if (function=="AVG") |
272 | return functionAvg(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 272 | return functionAvg(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
273 | if (function=="ABS") | 273 | if (function=="ABS") |
274 | return fabs(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 274 | return fabs(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
275 | if (function=="SIN") | 275 | if (function=="SIN") |
276 | return sin(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 276 | return sin(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
@@ -327,257 +327,257 @@ QChar Sheet::popCharStack(QStack<QChar> *stackChars) | |||
327 | if (stackChars->isEmpty()) | 327 | if (stackChars->isEmpty()) |
328 | { | 328 | { |
329 | QMessageBox::critical(this, tr("Error"), tr("Syntax error!")); | 329 | QMessageBox::critical(this, tr("Error"), tr("Syntax error!")); |
330 | return '0'; | 330 | return '0'; |
331 | } | 331 | } |
332 | 332 | ||
333 | QChar *temp=stackChars->pop(); | 333 | QChar *temp=stackChars->pop(); |
334 | QChar temp2(*temp); | 334 | QChar temp2(*temp); |
335 | delete temp; | 335 | delete temp; |
336 | return temp2; | 336 | return temp2; |
337 | } | 337 | } |
338 | 338 | ||
339 | QString Sheet::popStringStack(QStack<QString> *stackStrings) | 339 | QString Sheet::popStringStack(QStack<QString> *stackStrings) |
340 | { | 340 | { |
341 | if (stackStrings->isEmpty()) | 341 | if (stackStrings->isEmpty()) |
342 | { | 342 | { |
343 | QMessageBox::critical(this, tr("Error"), tr("Syntax error!")); | 343 | QMessageBox::critical(this, tr("Error"), tr("Syntax error!")); |
344 | return "0"; | 344 | return "0"; |
345 | } | 345 | } |
346 | 346 | ||
347 | QString *temp=stackStrings->pop(); | 347 | QString *temp=stackStrings->pop(); |
348 | QString temp2(*temp); | 348 | QString temp2(*temp); |
349 | delete temp; | 349 | delete temp; |
350 | return temp2; | 350 | return temp2; |
351 | } | 351 | } |
352 | 352 | ||
353 | QString Sheet::dataParserHelper(const QString &data) | 353 | QString Sheet::dataParserHelper(const QString &data) |
354 | { | 354 | { |
355 | QStack<QString> stackElements; | 355 | QStack<QString> stackElements; |
356 | QStack<QChar> stackOperators; | 356 | QStack<QChar> stackOperators; |
357 | QString tempElement(""), temp2Element, firstElement, secondElement; | 357 | QString tempElement(""), temp2Element, firstElement, secondElement; |
358 | int paranCount; | 358 | int paranCount; |
359 | 359 | ||
360 | for (unsigned int i=0; i<data.length(); ++i) | 360 | for (unsigned int i=0; i<data.length(); ++i) |
361 | { | 361 | { |
362 | if (data[i]=='+' || data[i]=='-' || data[i]=='*' || data[i]=='/') | 362 | if (data[i]=='+' || data[i]=='-' || data[i]=='*' || data[i]=='/') |
363 | { | 363 | { |
364 | pushStringStack(&stackElements, tempElement); | 364 | pushStringStack(&stackElements, tempElement); |
365 | tempElement=""; | 365 | tempElement=""; |
366 | if (!stackOperators.isEmpty() && getOperatorPriority(*stackOperators.top())>getOperatorPriority(data[i])) | 366 | if (!stackOperators.isEmpty() && getOperatorPriority(*stackOperators.top())>getOperatorPriority(data[i])) |
367 | { | 367 | { |
368 | secondElement=popStringStack(&stackElements); | 368 | secondElement=popStringStack(&stackElements); |
369 | firstElement=popStringStack(&stackElements); | 369 | firstElement=popStringStack(&stackElements); |
370 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); | 370 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); |
371 | } | 371 | } |
372 | pushCharStack(&stackOperators, data[i]); | 372 | pushCharStack(&stackOperators, data[i]); |
373 | } | 373 | } |
374 | else | 374 | else |
375 | if (data[i]==',') | 375 | if (data[i]==',') |
376 | { | 376 | { |
377 | if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement); | 377 | if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement); |
378 | while (!stackOperators.isEmpty()) | 378 | while (!stackOperators.isEmpty()) |
379 | { | 379 | { |
380 | secondElement=popStringStack(&stackElements); | 380 | secondElement=popStringStack(&stackElements); |
381 | firstElement=popStringStack(&stackElements); | 381 | firstElement=popStringStack(&stackElements); |
382 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); | 382 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); |
383 | } | 383 | } |
384 | tempElement=""; | 384 | tempElement=""; |
385 | } | 385 | } |
386 | else | 386 | else |
387 | if (data[i]=='(') | 387 | if (data[i]=='(') |
388 | { | 388 | { |
389 | paranCount=1; | 389 | paranCount=1; |
390 | temp2Element=""; | 390 | temp2Element=""; |
391 | for (++i; paranCount>0; ++i) | 391 | for (++i; paranCount>0; ++i) |
392 | { | 392 | { |
393 | temp2Element+=data[i]; | 393 | temp2Element+=data[i]; |
394 | if (data[i]=='(') ++paranCount; | 394 | if (data[i]=='(') ++paranCount; |
395 | if (data[i]==')') --paranCount; | 395 | if (data[i]==')') --paranCount; |
396 | } | 396 | } |
397 | temp2Element=dataParserHelper(temp2Element.left(temp2Element.length()-1)); | 397 | temp2Element=dataParserHelper(temp2Element.left(temp2Element.length()-1)); |
398 | if (tempElement.isEmpty()) | 398 | if (tempElement.isEmpty()) |
399 | tempElement=temp2Element; | 399 | tempElement=temp2Element; |
400 | else | 400 | else |
401 | tempElement.setNum(calculateFunction(tempElement, temp2Element)); | 401 | tempElement.setNum(calculateFunction(tempElement, temp2Element)); |
402 | --i; | 402 | --i; |
403 | } | 403 | } |
404 | else | 404 | else |
405 | tempElement+=data[i]; | 405 | tempElement+=data[i]; |
406 | } | 406 | } |
407 | if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement); | 407 | if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement); |
408 | while (!stackOperators.isEmpty()) | 408 | while (!stackOperators.isEmpty()) |
409 | { | 409 | { |
410 | secondElement=popStringStack(&stackElements); | 410 | secondElement=popStringStack(&stackElements); |
411 | firstElement=popStringStack(&stackElements); | 411 | firstElement=popStringStack(&stackElements); |
412 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); | 412 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); |
413 | } | 413 | } |
414 | 414 | ||
415 | if (!stackElements.isEmpty()) | 415 | if (!stackElements.isEmpty()) |
416 | tempElement=popStringStack(&stackElements); | 416 | tempElement=popStringStack(&stackElements); |
417 | while (!stackElements.isEmpty()) | 417 | while (!stackElements.isEmpty()) |
418 | tempElement.prepend(popStringStack(&stackElements)+","); | 418 | tempElement.prepend(popStringStack(&stackElements)+","); |
419 | return tempElement; | 419 | return tempElement; |
420 | } | 420 | } |
421 | 421 | ||
422 | QString Sheet::dataParser(const QString &data) | 422 | QString Sheet::dataParser(const QString &data) |
423 | { | 423 | { |
424 | QString strippedData(data); | 424 | QString strippedData(data); |
425 | strippedData.replace(QRegExp("\\s"), ""); | 425 | strippedData.replace(QRegExp("\\s"), ""); |
426 | if (strippedData.isEmpty() || strippedData[0]!='=') return data; | 426 | if (strippedData.isEmpty() || strippedData[0]!='=') return data; |
427 | strippedData=dataParserHelper(strippedData.remove(0, 1).upper().replace(QRegExp(":"), ",")); | 427 | strippedData=dataParserHelper(strippedData.remove(0, 1).upper().replace(QRegExp(":"), ",")); |
428 | 428 | ||
429 | int i=0; | 429 | int i=0; |
430 | QString tempParameter(getParameter(strippedData, i)), result=""; | 430 | QString tempParameter(getParameter(strippedData, i)), result=""; |
431 | do | 431 | do |
432 | { | 432 | { |
433 | result+=","+QString::number(calculateVariable(tempParameter)); | 433 | result+=","+QString::number(calculateVariable(tempParameter)); |
434 | tempParameter=getParameter(strippedData, ++i); | 434 | tempParameter=getParameter(strippedData, ++i); |
435 | } | 435 | } |
436 | while (!tempParameter.isNull()); | 436 | while (!tempParameter.isNull()); |
437 | return result.mid(1); | 437 | return result.mid(1); |
438 | } | 438 | } |
439 | 439 | ||
440 | void Sheet::setData(const QString &data) | 440 | void Sheet::setData(const QString &data) |
441 | { | 441 | { |
442 | setText(currentRow(), currentColumn(), data); | 442 | setText(currentRow(), currentColumn(), data); |
443 | slotCellChanged(currentRow(), currentColumn()); | 443 | slotCellChanged(currentRow(), currentColumn()); |
444 | activateNextCell(); | 444 | activateNextCell(); |
445 | } | 445 | } |
446 | 446 | ||
447 | QString Sheet::getData() | 447 | QString Sheet::getData() |
448 | { | 448 | { |
449 | typeCellData *cellData=findCellData(currentRow(), currentColumn()); | 449 | typeCellData *cellData=findCellData(currentRow(), currentColumn()); |
450 | if (cellData) | 450 | if (cellData) |
451 | return cellData->data; | 451 | return cellData->data; |
452 | return ""; | 452 | return ""; |
453 | } | 453 | } |
454 | 454 | ||
455 | void Sheet::lockClicks(bool lock=TRUE) | 455 | void Sheet::lockClicks(bool lock) |
456 | { | 456 | { |
457 | clicksLocked=lock; | 457 | clicksLocked=lock; |
458 | } | 458 | } |
459 | 459 | ||
460 | void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected) | 460 | void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected) |
461 | { | 461 | { |
462 | if (selected && row==currentRow() && col==currentColumn()) selected=FALSE; | 462 | if (selected && row==currentRow() && col==currentColumn()) selected=FALSE; |
463 | 463 | ||
464 | int sheetDataCurrent=sheetData.at(); | 464 | int sheetDataCurrent=sheetData.at(); |
465 | typeCellData *cellData=findCellData(row, col); | 465 | typeCellData *cellData=findCellData(row, col); |
466 | if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent); | 466 | if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent); |
467 | if (!cellData) cellData=&defaultCellData; | 467 | if (!cellData) cellData=&defaultCellData; |
468 | if (selected) | 468 | if (selected) |
469 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight()); | 469 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight()); |
470 | else | 470 | else |
471 | { | 471 | { |
472 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base()); | 472 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base()); |
473 | p->fillRect(0, 0, cr.width(), cr.height(), cellData->background); | 473 | p->fillRect(0, 0, cr.width(), cr.height(), cellData->background); |
474 | } | 474 | } |
475 | 475 | ||
476 | QTableItem *cellItem=item(row, col); | 476 | QTableItem *cellItem=item(row, col); |
477 | if (cellItem) | 477 | if (cellItem) |
478 | { | 478 | { |
479 | p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor); | 479 | p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor); |
480 | p->setFont(cellData->font); | 480 | p->setFont(cellData->font); |
481 | p->drawText(2, 2, cr.width()-4, cr.height()-4, cellData->alignment, cellItem->text()); | 481 | p->drawText(2, 2, cr.width()-4, cr.height()-4, cellData->alignment, cellItem->text()); |
482 | } | 482 | } |
483 | 483 | ||
484 | int rx=cr.width()-1, ry=cr.height()-1; | 484 | int rx=cr.width()-1, ry=cr.height()-1; |
485 | QPen pen(p->pen()); | 485 | QPen pen(p->pen()); |
486 | p->setPen(cellData->borders.right); | 486 | p->setPen(cellData->borders.right); |
487 | p->drawLine(rx, 0, rx, ry); | 487 | p->drawLine(rx, 0, rx, ry); |
488 | p->setPen(cellData->borders.bottom); | 488 | p->setPen(cellData->borders.bottom); |
489 | p->drawLine(0, ry, rx, ry); | 489 | p->drawLine(0, ry, rx, ry); |
490 | p->setPen(pen); | 490 | p->setPen(pen); |
491 | } | 491 | } |
492 | 492 | ||
493 | void Sheet::viewportMousePressEvent(QMouseEvent *e) | 493 | void Sheet::viewportMousePressEvent(QMouseEvent *e) |
494 | { | 494 | { |
495 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); | 495 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); |
496 | if (clicksLocked) | 496 | if (clicksLocked) |
497 | { | 497 | { |
498 | if (selectionNo<0) | 498 | if (selectionNo<0) |
499 | { | 499 | { |
500 | clearSelection(); | 500 | clearSelection(); |
501 | QTableSelection newSelection; | 501 | QTableSelection newSelection; |
502 | newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x())); | 502 | newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x())); |
503 | newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol()); | 503 | newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol()); |
504 | selectionNo=addSelection(newSelection); | 504 | selectionNo=addSelection(newSelection); |
505 | } | 505 | } |
506 | } | 506 | } |
507 | else | 507 | else |
508 | QTable::contentsMousePressEvent(&ce); | 508 | QTable::contentsMousePressEvent(&ce); |
509 | } | 509 | } |
510 | 510 | ||
511 | void Sheet::viewportMouseMoveEvent(QMouseEvent *e) | 511 | void Sheet::viewportMouseMoveEvent(QMouseEvent *e) |
512 | { | 512 | { |
513 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); | 513 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); |
514 | if (clicksLocked) | 514 | if (clicksLocked) |
515 | { | 515 | { |
516 | if (selectionNo>=0) | 516 | if (selectionNo>=0) |
517 | { | 517 | { |
518 | QTableSelection oldSelection(selection(selectionNo)); | 518 | QTableSelection oldSelection(selection(selectionNo)); |
519 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); | 519 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); |
520 | if (!(oldSelection==selection(selectionNo))) | 520 | if (!(oldSelection==selection(selectionNo))) |
521 | { | 521 | { |
522 | removeSelection(selectionNo); | 522 | removeSelection(selectionNo); |
523 | selectionNo=addSelection(oldSelection); | 523 | selectionNo=addSelection(oldSelection); |
524 | } | 524 | } |
525 | } | 525 | } |
526 | } | 526 | } |
527 | else | 527 | else |
528 | QTable::contentsMouseMoveEvent(&ce); | 528 | QTable::contentsMouseMoveEvent(&ce); |
529 | } | 529 | } |
530 | 530 | ||
531 | void Sheet::viewportMouseReleaseEvent(QMouseEvent *e) | 531 | void Sheet::viewportMouseReleaseEvent(QMouseEvent *e) |
532 | { | 532 | { |
533 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); | 533 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); |
534 | if (clicksLocked && selectionNo>=0) | 534 | if (clicksLocked && selectionNo>=0) |
535 | { | 535 | { |
536 | QTableSelection oldSelection(selection(selectionNo)); | 536 | QTableSelection oldSelection(selection(selectionNo)); |
537 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); | 537 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); |
538 | removeSelection(selectionNo); | 538 | removeSelection(selectionNo); |
539 | selectionNo=-1; | 539 | selectionNo=-1; |
540 | if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol()) | 540 | if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol()) |
541 | emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1)); | 541 | emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1)); |
542 | else | 542 | else |
543 | emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1)+','+getHeaderString(oldSelection.rightCol()+1)+QString::number(oldSelection.bottomRow()+1)); | 543 | emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1)+','+getHeaderString(oldSelection.rightCol()+1)+QString::number(oldSelection.bottomRow()+1)); |
544 | } | 544 | } |
545 | else | 545 | else |
546 | QTable::contentsMouseReleaseEvent(&ce); | 546 | QTable::contentsMouseReleaseEvent(&ce); |
547 | } | 547 | } |
548 | 548 | ||
549 | void Sheet::copySheetData(QList<typeCellData> *destSheetData) | 549 | void Sheet::copySheetData(QList<typeCellData> *destSheetData) |
550 | { | 550 | { |
551 | typeCellData *tempCellData, *newCellData; | 551 | typeCellData *tempCellData, *newCellData; |
552 | destSheetData->clear(); | 552 | destSheetData->clear(); |
553 | 553 | ||
554 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 554 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
555 | { | 555 | { |
556 | newCellData=new typeCellData; | 556 | newCellData=new typeCellData; |
557 | *newCellData=*tempCellData; | 557 | *newCellData=*tempCellData; |
558 | destSheetData->append(newCellData); | 558 | destSheetData->append(newCellData); |
559 | } | 559 | } |
560 | } | 560 | } |
561 | 561 | ||
562 | void Sheet::setSheetData(QList<typeCellData> *srcSheetData) | 562 | void Sheet::setSheetData(QList<typeCellData> *srcSheetData) |
563 | { | 563 | { |
564 | typeCellData *tempCellData, *newCellData; | 564 | typeCellData *tempCellData, *newCellData; |
565 | 565 | ||
566 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 566 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
567 | { | 567 | { |
568 | clearCell(tempCellData->row, tempCellData->col); | 568 | clearCell(tempCellData->row, tempCellData->col); |
569 | updateCell(tempCellData->row, tempCellData->col); | 569 | updateCell(tempCellData->row, tempCellData->col); |
570 | } | 570 | } |
571 | sheetData.clear(); | 571 | sheetData.clear(); |
572 | 572 | ||
573 | for (tempCellData=srcSheetData->first(); tempCellData; tempCellData=srcSheetData->next()) | 573 | for (tempCellData=srcSheetData->first(); tempCellData; tempCellData=srcSheetData->next()) |
574 | { | 574 | { |
575 | newCellData=new typeCellData; | 575 | newCellData=new typeCellData; |
576 | *newCellData=*tempCellData; | 576 | *newCellData=*tempCellData; |
577 | sheetData.append(newCellData); | 577 | sheetData.append(newCellData); |
578 | setText(newCellData->row, newCellData->col, dataParser(newCellData->data)); | 578 | setText(newCellData->row, newCellData->col, dataParser(newCellData->data)); |
579 | } | 579 | } |
580 | emit sheetModified(); | 580 | emit sheetModified(); |
581 | } | 581 | } |
582 | 582 | ||
583 | void Sheet::setName(const QString &name) | 583 | void Sheet::setName(const QString &name) |
@@ -611,253 +611,253 @@ QBrush Sheet::getBrush(int row, int col) | |||
611 | 611 | ||
612 | void Sheet::setTextAlign(int row, int col, Qt::AlignmentFlags flags) | 612 | void Sheet::setTextAlign(int row, int col, Qt::AlignmentFlags flags) |
613 | { | 613 | { |
614 | typeCellData *cellData=findCellData(row, col); | 614 | typeCellData *cellData=findCellData(row, col); |
615 | if (!cellData) cellData=createCellData(row, col); | 615 | if (!cellData) cellData=createCellData(row, col); |
616 | if (cellData) | 616 | if (cellData) |
617 | { | 617 | { |
618 | cellData->alignment=flags; | 618 | cellData->alignment=flags; |
619 | emit sheetModified(); | 619 | emit sheetModified(); |
620 | } | 620 | } |
621 | } | 621 | } |
622 | 622 | ||
623 | Qt::AlignmentFlags Sheet::getAlignment(int row, int col) | 623 | Qt::AlignmentFlags Sheet::getAlignment(int row, int col) |
624 | { | 624 | { |
625 | typeCellData *cellData=findCellData(row, col); | 625 | typeCellData *cellData=findCellData(row, col); |
626 | if (!cellData) cellData=&defaultCellData; | 626 | if (!cellData) cellData=&defaultCellData; |
627 | return cellData->alignment; | 627 | return cellData->alignment; |
628 | } | 628 | } |
629 | 629 | ||
630 | void Sheet::setTextFont(int row, int col, const QFont &font, const QColor &color) | 630 | void Sheet::setTextFont(int row, int col, const QFont &font, const QColor &color) |
631 | { | 631 | { |
632 | typeCellData *cellData=findCellData(row, col); | 632 | typeCellData *cellData=findCellData(row, col); |
633 | if (!cellData) cellData=createCellData(row, col); | 633 | if (!cellData) cellData=createCellData(row, col); |
634 | if (cellData) | 634 | if (cellData) |
635 | { | 635 | { |
636 | cellData->font=font; | 636 | cellData->font=font; |
637 | cellData->fontColor=color; | 637 | cellData->fontColor=color; |
638 | emit sheetModified(); | 638 | emit sheetModified(); |
639 | } | 639 | } |
640 | } | 640 | } |
641 | 641 | ||
642 | QFont Sheet::getFont(int row, int col) | 642 | QFont Sheet::getFont(int row, int col) |
643 | { | 643 | { |
644 | typeCellData *cellData=findCellData(row, col); | 644 | typeCellData *cellData=findCellData(row, col); |
645 | if (!cellData) cellData=&defaultCellData; | 645 | if (!cellData) cellData=&defaultCellData; |
646 | return cellData->font; | 646 | return cellData->font; |
647 | } | 647 | } |
648 | 648 | ||
649 | QColor Sheet::getFontColor(int row, int col) | 649 | QColor Sheet::getFontColor(int row, int col) |
650 | { | 650 | { |
651 | typeCellData *cellData=findCellData(row, col); | 651 | typeCellData *cellData=findCellData(row, col); |
652 | if (!cellData) cellData=&defaultCellData; | 652 | if (!cellData) cellData=&defaultCellData; |
653 | return cellData->fontColor; | 653 | return cellData->fontColor; |
654 | } | 654 | } |
655 | 655 | ||
656 | void Sheet::setPen(int row, int col, int vertical, const QPen &pen) | 656 | void Sheet::setPen(int row, int col, int vertical, const QPen &pen) |
657 | { | 657 | { |
658 | typeCellData *cellData=findCellData(row, col); | 658 | typeCellData *cellData=findCellData(row, col); |
659 | if (!cellData) cellData=createCellData(row, col); | 659 | if (!cellData) cellData=createCellData(row, col); |
660 | if (cellData) | 660 | if (cellData) |
661 | { | 661 | { |
662 | if (vertical) | 662 | if (vertical) |
663 | cellData->borders.right=pen; | 663 | cellData->borders.right=pen; |
664 | else | 664 | else |
665 | cellData->borders.bottom=pen; | 665 | cellData->borders.bottom=pen; |
666 | emit sheetModified(); | 666 | emit sheetModified(); |
667 | } | 667 | } |
668 | } | 668 | } |
669 | 669 | ||
670 | QPen Sheet::getPen(int row, int col, int vertical) | 670 | QPen Sheet::getPen(int row, int col, int vertical) |
671 | { | 671 | { |
672 | typeCellData *cellData=findCellData(row, col); | 672 | typeCellData *cellData=findCellData(row, col); |
673 | if (!cellData) cellData=&defaultCellData; | 673 | if (!cellData) cellData=&defaultCellData; |
674 | return (vertical ? cellData->borders.right : cellData->borders.bottom); | 674 | return (vertical ? cellData->borders.right : cellData->borders.bottom); |
675 | } | 675 | } |
676 | 676 | ||
677 | void Sheet::getSelection(int *row1, int *col1, int *row2, int *col2) | 677 | void Sheet::getSelection(int *row1, int *col1, int *row2, int *col2) |
678 | { | 678 | { |
679 | int selectionNo=currentSelection(); | 679 | int selectionNo=currentSelection(); |
680 | if (selectionNo>=0) | 680 | if (selectionNo>=0) |
681 | { | 681 | { |
682 | QTableSelection selection(selection(selectionNo)); | 682 | QTableSelection selection(selection(selectionNo)); |
683 | *row1=selection.topRow(); | 683 | *row1=selection.topRow(); |
684 | *row2=selection.bottomRow(); | 684 | *row2=selection.bottomRow(); |
685 | *col1=selection.leftCol(); | 685 | *col1=selection.leftCol(); |
686 | *col2=selection.rightCol(); | 686 | *col2=selection.rightCol(); |
687 | } | 687 | } |
688 | else | 688 | else |
689 | { | 689 | { |
690 | *row1=*row2=currentRow(); | 690 | *row1=*row2=currentRow(); |
691 | *col1=*col2=currentColumn(); | 691 | *col1=*col2=currentColumn(); |
692 | } | 692 | } |
693 | } | 693 | } |
694 | 694 | ||
695 | void Sheet::editClear() | 695 | void Sheet::editClear() |
696 | { | 696 | { |
697 | int row1, row2, col1, col2; | 697 | int row1, row2, col1, col2; |
698 | getSelection(&row1, &col1, &row2, &col2); | 698 | getSelection(&row1, &col1, &row2, &col2); |
699 | 699 | ||
700 | int row, col; | 700 | int row, col; |
701 | for (row=row1; row<=row2; ++row) | 701 | for (row=row1; row<=row2; ++row) |
702 | for (col=col1; col<=col2; ++col) | 702 | for (col=col1; col<=col2; ++col) |
703 | { | 703 | { |
704 | setText(row, col, ""); | 704 | setText(row, col, ""); |
705 | slotCellChanged(row, col); | 705 | slotCellChanged(row, col); |
706 | } | 706 | } |
707 | } | 707 | } |
708 | 708 | ||
709 | void Sheet::editCopy() | 709 | void Sheet::editCopy() |
710 | { | 710 | { |
711 | clipboardData.clear(); | 711 | clipboardData.clear(); |
712 | 712 | ||
713 | int row1, row2, col1, col2; | 713 | int row1, row2, col1, col2; |
714 | getSelection(&row1, &col1, &row2, &col2); | 714 | getSelection(&row1, &col1, &row2, &col2); |
715 | 715 | ||
716 | typeCellData *cellData, *newCellData; | 716 | typeCellData *cellData, *newCellData; |
717 | int row, col; | 717 | int row, col; |
718 | for (row=row1; row<=row2; ++row) | 718 | for (row=row1; row<=row2; ++row) |
719 | for (col=col1; col<=col2; ++col) | 719 | for (col=col1; col<=col2; ++col) |
720 | { | 720 | { |
721 | cellData=findCellData(row, col); | 721 | cellData=findCellData(row, col); |
722 | if (cellData) | 722 | if (cellData) |
723 | { | 723 | { |
724 | newCellData=new typeCellData; | 724 | newCellData=new typeCellData; |
725 | *newCellData=*cellData; | 725 | *newCellData=*cellData; |
726 | newCellData->row-=row1; | 726 | newCellData->row-=row1; |
727 | newCellData->col-=col1; | 727 | newCellData->col-=col1; |
728 | clipboardData.append(newCellData); | 728 | clipboardData.append(newCellData); |
729 | } | 729 | } |
730 | } | 730 | } |
731 | } | 731 | } |
732 | 732 | ||
733 | void Sheet::editCut() | 733 | void Sheet::editCut() |
734 | { | 734 | { |
735 | editCopy(); | 735 | editCopy(); |
736 | editClear(); | 736 | editClear(); |
737 | } | 737 | } |
738 | 738 | ||
739 | void Sheet::editPaste(bool onlyContents=FALSE) | 739 | void Sheet::editPaste(bool onlyContents) |
740 | { | 740 | { |
741 | int row1=currentRow(), col1=currentColumn(); | 741 | int row1=currentRow(), col1=currentColumn(); |
742 | typeCellData *cellData, *tempCellData; | 742 | typeCellData *cellData, *tempCellData; |
743 | 743 | ||
744 | for (tempCellData=clipboardData.first(); tempCellData; tempCellData=clipboardData.next()) | 744 | for (tempCellData=clipboardData.first(); tempCellData; tempCellData=clipboardData.next()) |
745 | { | 745 | { |
746 | cellData=findCellData(tempCellData->row+row1, tempCellData->col+col1); | 746 | cellData=findCellData(tempCellData->row+row1, tempCellData->col+col1); |
747 | if (!cellData) cellData=createCellData(tempCellData->row+row1, tempCellData->col+col1); | 747 | if (!cellData) cellData=createCellData(tempCellData->row+row1, tempCellData->col+col1); |
748 | if (cellData) | 748 | if (cellData) |
749 | { | 749 | { |
750 | if (onlyContents) | 750 | if (onlyContents) |
751 | cellData->data=tempCellData->data; | 751 | cellData->data=tempCellData->data; |
752 | else | 752 | else |
753 | { | 753 | { |
754 | *cellData=*tempCellData; | 754 | *cellData=*tempCellData; |
755 | cellData->row+=row1; | 755 | cellData->row+=row1; |
756 | cellData->col+=col1; | 756 | cellData->col+=col1; |
757 | } | 757 | } |
758 | setText(cellData->row, cellData->col, dataParser(cellData->data)); | 758 | setText(cellData->row, cellData->col, dataParser(cellData->data)); |
759 | emit sheetModified(); | 759 | emit sheetModified(); |
760 | } | 760 | } |
761 | } | 761 | } |
762 | } | 762 | } |
763 | 763 | ||
764 | void Sheet::insertRows(int no=1, bool allColumns=TRUE) | 764 | void Sheet::insertRows(int no, bool allColumns) |
765 | { | 765 | { |
766 | setNumRows(numRows()+no); | 766 | setNumRows(numRows()+no); |
767 | 767 | ||
768 | typeCellData *tempCellData; | 768 | typeCellData *tempCellData; |
769 | int row=currentRow(), col=currentColumn(); | 769 | int row=currentRow(), col=currentColumn(); |
770 | 770 | ||
771 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 771 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
772 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) | 772 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) |
773 | { | 773 | { |
774 | clearCell(tempCellData->row, tempCellData->col); | 774 | clearCell(tempCellData->row, tempCellData->col); |
775 | tempCellData->row+=no; | 775 | tempCellData->row+=no; |
776 | } | 776 | } |
777 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 777 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
778 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) | 778 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) |
779 | { | 779 | { |
780 | updateCell(tempCellData->row-no, tempCellData->col); | 780 | updateCell(tempCellData->row-no, tempCellData->col); |
781 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); | 781 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); |
782 | } | 782 | } |
783 | emit sheetModified(); | 783 | emit sheetModified(); |
784 | } | 784 | } |
785 | 785 | ||
786 | void Sheet::insertColumns(int no=1, bool allRows=TRUE) | 786 | void Sheet::insertColumns(int no, bool allRows) |
787 | { | 787 | { |
788 | int noCols=numCols(); | 788 | int noCols=numCols(); |
789 | int newCols=noCols+no; | 789 | int newCols=noCols+no; |
790 | setNumCols(newCols); | 790 | setNumCols(newCols); |
791 | for (int i=noCols; i<newCols; ++i) | 791 | for (int i=noCols; i<newCols; ++i) |
792 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); | 792 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); |
793 | 793 | ||
794 | typeCellData *tempCellData; | 794 | typeCellData *tempCellData; |
795 | int col=currentColumn(), row=currentRow(); | 795 | int col=currentColumn(), row=currentRow(); |
796 | 796 | ||
797 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 797 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
798 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) | 798 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) |
799 | { | 799 | { |
800 | clearCell(tempCellData->row, tempCellData->col); | 800 | clearCell(tempCellData->row, tempCellData->col); |
801 | tempCellData->col+=no; | 801 | tempCellData->col+=no; |
802 | } | 802 | } |
803 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 803 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
804 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) | 804 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) |
805 | { | 805 | { |
806 | updateCell(tempCellData->row, tempCellData->col-no); | 806 | updateCell(tempCellData->row, tempCellData->col-no); |
807 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); | 807 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); |
808 | } | 808 | } |
809 | emit sheetModified(); | 809 | emit sheetModified(); |
810 | } | 810 | } |
811 | 811 | ||
812 | void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE) | 812 | void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, bool matchCase, bool allCells, bool entireCell, bool replace, bool replaceAll) |
813 | { | 813 | { |
814 | typeCellData *tempCellData; | 814 | typeCellData *tempCellData; |
815 | int row1, col1, row2, col2; | 815 | int row1, col1, row2, col2; |
816 | getSelection(&row1, &col1, &row2, &col2); | 816 | getSelection(&row1, &col1, &row2, &col2); |
817 | bool found=FALSE; | 817 | bool found=FALSE; |
818 | 818 | ||
819 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 819 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
820 | if (allCells || (tempCellData->row>=row1 && tempCellData->row<=row2 && tempCellData->col>=col1 && tempCellData->col<=col2)) | 820 | if (allCells || (tempCellData->row>=row1 && tempCellData->row<=row2 && tempCellData->col>=col1 && tempCellData->col<=col2)) |
821 | { | 821 | { |
822 | QTableItem *cellItem=item(tempCellData->row, tempCellData->col); | 822 | QTableItem *cellItem=item(tempCellData->row, tempCellData->col); |
823 | if (cellItem && (entireCell ? (matchCase ? cellItem->text()==findStr : cellItem->text().upper()==findStr.upper()) : cellItem->text().find(findStr, 0, matchCase)>=0)) | 823 | if (cellItem && (entireCell ? (matchCase ? cellItem->text()==findStr : cellItem->text().upper()==findStr.upper()) : cellItem->text().find(findStr, 0, matchCase)>=0)) |
824 | { | 824 | { |
825 | if (!found) | 825 | if (!found) |
826 | { | 826 | { |
827 | found=TRUE; | 827 | found=TRUE; |
828 | clearSelection(); | 828 | clearSelection(); |
829 | } | 829 | } |
830 | setCurrentCell(tempCellData->row, tempCellData->col); | 830 | setCurrentCell(tempCellData->row, tempCellData->col); |
831 | if (replace) | 831 | if (replace) |
832 | { | 832 | { |
833 | tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr); | 833 | tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr); |
834 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); | 834 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); |
835 | } | 835 | } |
836 | if (!replace || !replaceAll) break; | 836 | if (!replace || !replaceAll) break; |
837 | } | 837 | } |
838 | } | 838 | } |
839 | 839 | ||
840 | if (found) | 840 | if (found) |
841 | { | 841 | { |
842 | if (replace) | 842 | if (replace) |
843 | slotCellChanged(currentRow(), currentColumn()); | 843 | slotCellChanged(currentRow(), currentColumn()); |
844 | } | 844 | } |
845 | else | 845 | else |
846 | QMessageBox::warning(this, tr("Error"), tr("Search key not found!")); | 846 | QMessageBox::warning(this, tr("Error"), tr("Search key not found!")); |
847 | } | 847 | } |
848 | 848 | ||
849 | // | 849 | // |
850 | // Static functions | 850 | // Static functions |
851 | // | 851 | // |
852 | 852 | ||
853 | QString Sheet::getHeaderString(int section) | 853 | QString Sheet::getHeaderString(int section) |
854 | { | 854 | { |
855 | if (section<1) return ""; | 855 | if (section<1) return ""; |
856 | return getHeaderString((section-1)/26)+QChar('A'+(section-1)%26); | 856 | return getHeaderString((section-1)/26)+QChar('A'+(section-1)%26); |
857 | } | 857 | } |
858 | 858 | ||
859 | int Sheet::getHeaderColumn(const QString §ion) | 859 | int Sheet::getHeaderColumn(const QString §ion) |
860 | { | 860 | { |
861 | if (section.isEmpty()) return 0; | 861 | if (section.isEmpty()) return 0; |
862 | return (section[section.length()-1]-'A'+1)+getHeaderColumn(section.left(section.length()-1))*26; | 862 | return (section[section.length()-1]-'A'+1)+getHeaderColumn(section.left(section.length()-1))*26; |
863 | } | 863 | } |
diff --git a/noncore/apps/opie-sheet/sortdlg.cpp b/noncore/apps/opie-sheet/sortdlg.cpp index c60be0d..c2cdec8 100644 --- a/noncore/apps/opie-sheet/sortdlg.cpp +++ b/noncore/apps/opie-sheet/sortdlg.cpp | |||
@@ -1,192 +1,193 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | /* | 10 | /* |
11 | * Opie Sheet (formerly Sheet/Qt) | 11 | * Opie Sheet (formerly Sheet/Qt) |
12 | * by Serdar Ozler <sozler@sitebest.com> | 12 | * by Serdar Ozler <sozler@sitebest.com> |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <qlabel.h> | 15 | #include <qlabel.h> |
16 | #include <qradiobutton.h> | 16 | #include <qradiobutton.h> |
17 | #include <qmessagebox.h> | 17 | #include <qmessagebox.h> |
18 | #include "sortdlg.h" | 18 | #include "sortdlg.h" |
19 | 19 | ||
20 | SortDialog::SortDialog(QWidget *parent=0) | 20 | SortDialog::SortDialog(QWidget *parent) |
21 | :QDialog(parent, 0, TRUE) | 21 | :QDialog(parent, 0, TRUE) |
22 | { | 22 | { |
23 | // Main widget | 23 | // Main widget |
24 | tabs=new QTabWidget(this); | 24 | tabs=new QTabWidget(this); |
25 | widgetSort=new QWidget(tabs); | 25 | widgetSort=new QWidget(tabs); |
26 | widgetOptions=new QWidget(tabs); | 26 | widgetOptions=new QWidget(tabs); |
27 | tabs->addTab(widgetSort, tr("&Sort")); | 27 | tabs->addTab(widgetSort, tr("&Sort")); |
28 | tabs->addTab(widgetOptions, tr("&Options")); | 28 | tabs->addTab(widgetOptions, tr("&Options")); |
29 | 29 | ||
30 | // Sort tab | 30 | // Sort tab |
31 | comboFieldA=createFieldCombo(tr("&Sort by"), 10); | 31 | comboFieldA=createFieldCombo(tr("&Sort by"), 10); |
32 | groupOrderA=createOrderButtons(10); | 32 | groupOrderA=createOrderButtons(10); |
33 | comboFieldB=createFieldCombo(tr("&Then by"), 90); | 33 | comboFieldB=createFieldCombo(tr("&Then by"), 90); |
34 | groupOrderB=createOrderButtons(90); | 34 | groupOrderB=createOrderButtons(90); |
35 | comboFieldC=createFieldCombo(tr("Then &by"), 170); | 35 | comboFieldC=createFieldCombo(tr("Then &by"), 170); |
36 | groupOrderC=createOrderButtons(170); | 36 | groupOrderC=createOrderButtons(170); |
37 | 37 | ||
38 | // Options tab | 38 | // Options tab |
39 | checkCase=new QCheckBox(tr("&Case Sensitive"), widgetOptions); | 39 | checkCase=new QCheckBox(tr("&Case Sensitive"), widgetOptions); |
40 | checkCase->setGeometry(10, 10, 215, 20); | 40 | checkCase->setGeometry(10, 10, 215, 20); |
41 | checkCase->setChecked(TRUE); | 41 | checkCase->setChecked(TRUE); |
42 | 42 | ||
43 | groupDirection=new QVButtonGroup(tr("&Direction"), widgetOptions); | 43 | groupDirection=new QVButtonGroup(tr("&Direction"), widgetOptions); |
44 | groupDirection->setGeometry(10, 40, 215, 70); | 44 | groupDirection->setGeometry(10, 40, 215, 70); |
45 | QRadioButton *radio=new QRadioButton(tr("&Top to bottom (rows)"), groupDirection); | 45 | QRadioButton *radio=new QRadioButton(tr("&Top to bottom (rows)"), groupDirection); |
46 | radio=new QRadioButton(tr("&Left to right (columns)"), groupDirection); | 46 | radio=new QRadioButton(tr("&Left to right (columns)"), groupDirection); |
47 | groupDirection->setButton(0); | 47 | groupDirection->setButton(0); |
48 | connect(groupDirection, SIGNAL(clicked(int)), this, SLOT(directionChanged(int))); | 48 | connect(groupDirection, SIGNAL(clicked(int)), this, SLOT(directionChanged(int))); |
49 | 49 | ||
50 | // Main widget | 50 | // Main widget |
51 | box=new QVBoxLayout(this); | 51 | box=new QVBoxLayout(this); |
52 | box->addWidget(tabs); | 52 | box->addWidget(tabs); |
53 | 53 | ||
54 | setCaption(tr("Sort")); | 54 | setCaption(tr("Sort")); |
55 | } | 55 | } |
56 | 56 | ||
57 | SortDialog::~SortDialog() | 57 | SortDialog::~SortDialog() |
58 | { | 58 | { |
59 | } | 59 | } |
60 | 60 | ||
61 | QComboBox *SortDialog::createFieldCombo(const QString &caption, int y) | 61 | QComboBox *SortDialog::createFieldCombo(const QString &caption, int y) |
62 | { | 62 | { |
63 | QLabel *label=new QLabel(caption, widgetSort); | 63 | QLabel *label=new QLabel(caption, widgetSort); |
64 | label->setGeometry(10, y+5, 215, 20); | 64 | label->setGeometry(10, y+5, 215, 20); |
65 | QComboBox *combo=new QComboBox(FALSE, widgetSort); | 65 | QComboBox *combo=new QComboBox(FALSE, widgetSort); |
66 | combo->setGeometry(10, y+35, 105, 20); | 66 | combo->setGeometry(10, y+35, 105, 20); |
67 | label->setBuddy(combo); | 67 | label->setBuddy(combo); |
68 | return combo; | 68 | return combo; |
69 | } | 69 | } |
70 | 70 | ||
71 | QVButtonGroup *SortDialog::createOrderButtons(int y) | 71 | QVButtonGroup *SortDialog::createOrderButtons(int y) |
72 | { | 72 | { |
73 | QVButtonGroup *group=new QVButtonGroup(widgetSort); | 73 | QVButtonGroup *group=new QVButtonGroup(widgetSort); |
74 | group->setGeometry(125, y, 100, 60); | 74 | group->setGeometry(125, y, 100, 60); |
75 | QRadioButton *radio=new QRadioButton(tr("&Ascending"), group); | 75 | QRadioButton *radio=new QRadioButton(tr("&Ascending"), group); |
76 | radio=new QRadioButton(tr("&Descending"), group); | 76 | radio=new QRadioButton(tr("&Descending"), group); |
77 | group->setButton(0); | 77 | group->setButton(0); |
78 | return group; | 78 | return group; |
79 | } | 79 | } |
80 | 80 | ||
81 | void SortDialog::directionChanged(int id) | 81 | void SortDialog::directionChanged(int id) |
82 | { | 82 | { |
83 | direction=id; | 83 | direction=id; |
84 | fillFieldCombo(comboFieldA); | 84 | fillFieldCombo(comboFieldA); |
85 | fillFieldCombo(comboFieldB); | 85 | fillFieldCombo(comboFieldB); |
86 | fillFieldCombo(comboFieldC); | 86 | fillFieldCombo(comboFieldC); |
87 | } | 87 | } |
88 | 88 | ||
89 | void SortDialog::fillFieldCombo(QComboBox *combo) | 89 | void SortDialog::fillFieldCombo(QComboBox *combo) |
90 | { | 90 | { |
91 | combo->clear(); | 91 | combo->clear(); |
92 | if (direction) | 92 | if (direction) |
93 | for (int row=row1; row<=row2; ++row) | 93 | for (int row=row1; row<=row2; ++row) |
94 | combo->insertItem("Row "+QString::number(row+1)); | 94 | combo->insertItem("Row "+QString::number(row+1)); |
95 | else | 95 | else |
96 | for (int col=col1; col<=col2; ++col) | 96 | for (int col=col1; col<=col2; ++col) |
97 | combo->insertItem("Column "+Sheet::getHeaderString(col+1)); | 97 | combo->insertItem("Column "+Sheet::getHeaderString(col+1)); |
98 | } | 98 | } |
99 | 99 | ||
100 | int SortDialog::exec(Sheet *s) | 100 | int SortDialog::exec(Sheet *s) |
101 | { | 101 | { |
102 | sheet=s; | 102 | sheet=s; |
103 | sheet->getSelection(&row1, &col1, &row2, &col2); | 103 | sheet->getSelection(&row1, &col1, &row2, &col2); |
104 | 104 | ||
105 | direction=0; | 105 | direction=0; |
106 | fillFieldCombo(comboFieldA); | 106 | fillFieldCombo(comboFieldA); |
107 | fillFieldCombo(comboFieldB); | 107 | fillFieldCombo(comboFieldB); |
108 | fillFieldCombo(comboFieldC); | 108 | fillFieldCombo(comboFieldC); |
109 | 109 | ||
110 | if (row1==row2 && col1==col2) | 110 | if (row1==row2 && col1==col2) |
111 | { | 111 | { |
112 | QMessageBox::warning(this, tr("Error"), tr("One cell cannot be sorted!")); | 112 | QMessageBox::warning(this, tr("Error"), tr("One cell cannot be sorted!")); |
113 | return QDialog::Rejected; | 113 | return QDialog::Rejected; |
114 | } | 114 | } |
115 | if (QDialog::exec()==QDialog::Accepted) | 115 | if (QDialog::exec()==QDialog::Accepted) |
116 | { | 116 | { |
117 | QString field1S=comboFieldA->currentText(), field2S=comboFieldB->currentText(), field3S=comboFieldC->currentText(); | 117 | QString field1S=comboFieldA->currentText(), field2S=comboFieldB->currentText(), field3S=comboFieldC->currentText(); |
118 | field1S=field1S.mid(field1S.find(' ')+1); | 118 | field1S=field1S.mid(field1S.find(' ')+1); |
119 | field2S=field2S.mid(field2S.find(' ')+1); | 119 | field2S=field2S.mid(field2S.find(' ')+1); |
120 | field3S=field3S.mid(field3S.find(' ')+1); | 120 | field3S=field3S.mid(field3S.find(' ')+1); |
121 | int field1, field2, field3; | 121 | int field1, field2, field3; |
122 | if (direction) | 122 | if (direction) |
123 | { | 123 | { |
124 | field1=field1S.toInt()-1; | 124 | field1=field1S.toInt()-1; |
125 | field2=field2S.toInt()-1; | 125 | field2=field2S.toInt()-1; |
126 | field3=field3S.toInt()-1; | 126 | field3=field3S.toInt()-1; |
127 | int i, j; | 127 | int i, j; |
128 | for (i=col2; i>=col1; --i) | 128 | for (i=col2; i>=col1; --i) |
129 | for (j=col1+1; j<=i; ++j) | 129 | for (j=col1+1; j<=i; ++j) |
130 | { | 130 | { |
131 | bool swap=FALSE; | 131 | bool swap=FALSE; |
132 | int compareResult=compareItems(s->item(field1, j-1), s->item(field1, j), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked()); | 132 | int compareResult=compareItems(s->item(field1, j-1), s->item(field1, j), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked()); |
133 | if (compareResult>0) swap=TRUE; | 133 | if (compareResult>0) swap=TRUE; |
134 | else if (compareResult==0) | 134 | else if (compareResult==0) |
135 | { | 135 | { |
136 | compareResult=compareItems(s->item(field2, j-1), s->item(field2, j), groupOrderB->id(groupOrderB->selected()), checkCase->isChecked()); | 136 | compareResult=compareItems(s->item(field2, j-1), s->item(field2, j), groupOrderB->id(groupOrderB->selected()), checkCase->isChecked()); |
137 | if (compareResult>0) swap=TRUE; | 137 | if (compareResult>0) swap=TRUE; |
138 | else if (compareResult==0) | 138 | else if (compareResult==0) |
139 | { | 139 | { |
140 | compareResult=compareItems(s->item(field3, j-1), s->item(field3, j), groupOrderC->id(groupOrderC->selected()), checkCase->isChecked()); | 140 | compareResult=compareItems(s->item(field3, j-1), s->item(field3, j), groupOrderC->id(groupOrderC->selected()), checkCase->isChecked()); |
141 | if (compareResult>0) swap=TRUE; | 141 | if (compareResult>0) swap=TRUE; |
142 | } | 142 | } |
143 | } | 143 | } |
144 | if (swap) | 144 | if (swap) |
145 | for (int row=row1; row<=row2; ++row) | 145 | for (int row=row1; row<=row2; ++row) |
146 | s->swapCells(row, j-1, row, j); | 146 | s->swapCells(row, j-1, row, j); |
147 | } | 147 | } |
148 | } | 148 | } |
149 | else | 149 | else |
150 | { | 150 | { |
151 | field1=Sheet::getHeaderColumn(field1S)-1; | 151 | field1=Sheet::getHeaderColumn(field1S)-1; |
152 | field2=Sheet::getHeaderColumn(field2S)-1; | 152 | field2=Sheet::getHeaderColumn(field2S)-1; |
153 | field3=Sheet::getHeaderColumn(field3S)-1; | 153 | field3=Sheet::getHeaderColumn(field3S)-1; |
154 | int i, j; | 154 | int i, j; |
155 | for (i=row2; i>=row1; --i) | 155 | for (i=row2; i>=row1; --i) |
156 | for (j=row1+1; j<=i; ++j) | 156 | for (j=row1+1; j<=i; ++j) |
157 | { | 157 | { |
158 | bool swap=FALSE; | 158 | bool swap=FALSE; |
159 | int compareResult=compareItems(s->item(j-1, field1), s->item(j, field1), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked()); | 159 | int compareResult=compareItems(s->item(j-1, field1), s->item(j, field1), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked()); |
160 | if (compareResult>0) swap=TRUE; | 160 | if (compareResult>0) swap=TRUE; |
161 | else if (compareResult==0) | 161 | else if (compareResult==0) |
162 | { | 162 | { |
163 | compareResult=compareItems(s->item(j-1, field2), s->item(j, field2), groupOrderB->id(groupOrderB->selected()), checkCase->isChecked()); | 163 | compareResult=compareItems(s->item(j-1, field2), s->item(j, field2), groupOrderB->id(groupOrderB->selected()), checkCase->isChecked()); |
164 | if (compareResult>0) swap=TRUE; | 164 | if (compareResult>0) swap=TRUE; |
165 | else if (compareResult==0) | 165 | else if (compareResult==0) |
166 | { | 166 | { |
167 | compareResult=compareItems(s->item(j-1, field3), s->item(j, field3), groupOrderC->id(groupOrderC->selected()), checkCase->isChecked()); | 167 | compareResult=compareItems(s->item(j-1, field3), s->item(j, field3), groupOrderC->id(groupOrderC->selected()), checkCase->isChecked()); |
168 | if (compareResult>0) swap=TRUE; | 168 | if (compareResult>0) swap=TRUE; |
169 | } | 169 | } |
170 | } | 170 | } |
171 | if (swap) | 171 | if (swap) |
172 | for (int col=col1; col<=col2; ++col) | 172 | for (int col=col1; col<=col2; ++col) |
173 | s->swapCells(j-1, col, j, col); | 173 | s->swapCells(j-1, col, j, col); |
174 | } | 174 | } |
175 | } | 175 | } |
176 | return QDialog::Accepted; | 176 | return QDialog::Accepted; |
177 | } | 177 | } |
178 | return QDialog::Rejected; | 178 | return QDialog::Rejected; |
179 | } | 179 | } |
180 | 180 | ||
181 | int SortDialog::compareItems(QTableItem *item1, QTableItem *item2, int descending=0, bool caseSensitive=TRUE) | 181 | int SortDialog::compareItems(QTableItem *item1, QTableItem *item2, |
182 | int descending, bool caseSensitive) | ||
182 | { | 183 | { |
183 | int result=0; | 184 | int result=0; |
184 | if (item1) | 185 | if (item1) |
185 | { | 186 | { |
186 | if (item2) result=(caseSensitive ? item1->text().compare(item2->text()) : item1->text().upper().compare(item2->text().upper())); | 187 | if (item2) result=(caseSensitive ? item1->text().compare(item2->text()) : item1->text().upper().compare(item2->text().upper())); |
187 | else result=-1; | 188 | else result=-1; |
188 | } | 189 | } |
189 | else | 190 | else |
190 | if (item2) result=1; | 191 | if (item2) result=1; |
191 | return (descending ? -result : result); | 192 | return (descending ? -result : result); |
192 | } | 193 | } |
diff --git a/noncore/apps/opie-sheet/textdlg.cpp b/noncore/apps/opie-sheet/textdlg.cpp index 0810eb2..34cec29 100644 --- a/noncore/apps/opie-sheet/textdlg.cpp +++ b/noncore/apps/opie-sheet/textdlg.cpp | |||
@@ -1,46 +1,47 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | /* | 10 | /* |
11 | * Opie Sheet (formerly Sheet/Qt) | 11 | * Opie Sheet (formerly Sheet/Qt) |
12 | * by Serdar Ozler <sozler@sitebest.com> | 12 | * by Serdar Ozler <sozler@sitebest.com> |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include "textdlg.h" | 15 | #include "textdlg.h" |
16 | 16 | ||
17 | TextDialog::TextDialog(QWidget *parent=0) | 17 | TextDialog::TextDialog(QWidget *parent) |
18 | :QDialog(parent, 0, TRUE) | 18 | :QDialog(parent, 0, TRUE) |
19 | { | 19 | { |
20 | edit=new QLineEdit(this); | 20 | edit=new QLineEdit(this); |
21 | edit->setGeometry(90, 10, 100, 25); | 21 | edit->setGeometry(90, 10, 100, 25); |
22 | 22 | ||
23 | label=new QLabel(this); | 23 | label=new QLabel(this); |
24 | label->setGeometry(10, 10, 70, 25); | 24 | label->setGeometry(10, 10, 70, 25); |
25 | label->setBuddy(edit); | 25 | label->setBuddy(edit); |
26 | 26 | ||
27 | resize(200, 45); | 27 | resize(200, 45); |
28 | } | 28 | } |
29 | 29 | ||
30 | TextDialog::~TextDialog() | 30 | TextDialog::~TextDialog() |
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | int TextDialog::exec(const QString &caption, const QString &text, const QString &value="") | 34 | int TextDialog::exec(const QString &caption, const QString &text, |
35 | const QString &value) | ||
35 | { | 36 | { |
36 | setCaption(caption); | 37 | setCaption(caption); |
37 | label->setText(text); | 38 | label->setText(text); |
38 | edit->setText(value); | 39 | edit->setText(value); |
39 | 40 | ||
40 | return QDialog::exec(); | 41 | return QDialog::exec(); |
41 | } | 42 | } |
42 | 43 | ||
43 | QString TextDialog::getValue() | 44 | QString TextDialog::getValue() |
44 | { | 45 | { |
45 | return edit->text(); | 46 | return edit->text(); |
46 | } | 47 | } |
diff --git a/noncore/tools/remote/helptab.cpp b/noncore/tools/remote/helptab.cpp index 3c53ab6..ac51e13 100644 --- a/noncore/tools/remote/helptab.cpp +++ b/noncore/tools/remote/helptab.cpp | |||
@@ -1,27 +1,27 @@ | |||
1 | /* | 1 | /* |
2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. | 2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. |
3 | Copyright (C) 2002 Thomas Stephens | 3 | Copyright (C) 2002 Thomas Stephens |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public | 5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public |
6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later | 6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later |
7 | version. | 7 | version. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | 9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | 10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11 | Public License for more details. | 11 | Public License for more details. |
12 | 12 | ||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | 13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free |
14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "helptab.h" | 17 | #include "helptab.h" |
18 | 18 | ||
19 | HelpTab::HelpTab(QWidget *parent=0, const char *name=0):QWidget(parent, name) | 19 | HelpTab::HelpTab(QWidget *parent, const char *name):QWidget(parent, name) |
20 | { | 20 | { |
21 | QVBoxLayout *layout = new QVBoxLayout(this); | 21 | QVBoxLayout *layout = new QVBoxLayout(this); |
22 | QString *string = new QString("<qt><h1>Opie-Remote Usage Instructions</h1><p>First, some definitions. A Remote is a remote entry in an lircd.conf file, it represents one remote you want to emulate. A Remote Layout is one entry in your ~/Settings/Remote.conf file. It represents the buttons that you see on your screen. Each button on a Remote Layout can be mapped to any button in a Remote. This way you can have, for example, a vcr remote layout, in which all the play/pause/etc buttons are mapped to the buttons on your vcr's remote. However, most VCR's don't have volume controls, so the volume buttons can be mapped to the volume buttons on your TV.</p><p>The first things you need the lirc and lirc-modules ipkgs. If you installed this from an ipkg, they should already be there, thanks to the wonderful world of dependencies. If not, get them. The next thing you need is an lircd.conf file. you can get these at <a href=http://www.lirc.org/>http://www.lirc.org/</a>. Read the documentation there to figure out how to make your own, if one for your remote doesn't exist, or how to have multiple remotes in one lircd.conf file. Once you have a good lircd.conf file, put it in /etc, kill the lircd daemon (if its running) and do a modprobe lirc_sir. Then, run lircd again.</p><p>The next thing you want to do is to create a remote layout. Go to the config tab, and enter a name for your remote layout in the pulldown menu. Dont use the name Remotes, as that could confuse the app. Hopefully, that will be fixed soon. after entering the name you want to use, press New, and then select the name again from the pulldown menu (another oddity that i hope to fix). Then, press each button that you want to map, and a dialog should appear. Select the remote and button that you want to use, and click OK. Once you are done, go to the Remote tab, and select the new remote from the dropdown menu. It should works fine. If at any time you want to change a remote layout, go to the Config tab, select the layout from the dropdown menu, and change the buttons you want to change.</p><p>This is program is written and maintaned by Thomas (spiralman) Stephens. <a href=mailto:spiralman@softhome.net>spiralman@softhome.net</a>. Or, look for me on #opie or #handhelds.org on irc.openprojects.net.</p></qt>"); | 22 | QString *string = new QString("<qt><h1>Opie-Remote Usage Instructions</h1><p>First, some definitions. A Remote is a remote entry in an lircd.conf file, it represents one remote you want to emulate. A Remote Layout is one entry in your ~/Settings/Remote.conf file. It represents the buttons that you see on your screen. Each button on a Remote Layout can be mapped to any button in a Remote. This way you can have, for example, a vcr remote layout, in which all the play/pause/etc buttons are mapped to the buttons on your vcr's remote. However, most VCR's don't have volume controls, so the volume buttons can be mapped to the volume buttons on your TV.</p><p>The first things you need the lirc and lirc-modules ipkgs. If you installed this from an ipkg, they should already be there, thanks to the wonderful world of dependencies. If not, get them. The next thing you need is an lircd.conf file. you can get these at <a href=http://www.lirc.org/>http://www.lirc.org/</a>. Read the documentation there to figure out how to make your own, if one for your remote doesn't exist, or how to have multiple remotes in one lircd.conf file. Once you have a good lircd.conf file, put it in /etc, kill the lircd daemon (if its running) and do a modprobe lirc_sir. Then, run lircd again.</p><p>The next thing you want to do is to create a remote layout. Go to the config tab, and enter a name for your remote layout in the pulldown menu. Dont use the name Remotes, as that could confuse the app. Hopefully, that will be fixed soon. after entering the name you want to use, press New, and then select the name again from the pulldown menu (another oddity that i hope to fix). Then, press each button that you want to map, and a dialog should appear. Select the remote and button that you want to use, and click OK. Once you are done, go to the Remote tab, and select the new remote from the dropdown menu. It should works fine. If at any time you want to change a remote layout, go to the Config tab, select the layout from the dropdown menu, and change the buttons you want to change.</p><p>This is program is written and maintaned by Thomas (spiralman) Stephens. <a href=mailto:spiralman@softhome.net>spiralman@softhome.net</a>. Or, look for me on #opie or #handhelds.org on irc.openprojects.net.</p></qt>"); |
23 | QTextView *view = new QTextView((const QString &)*string, 0, this, "view"); | 23 | QTextView *view = new QTextView((const QString &)*string, 0, this, "view"); |
24 | layout->insertSpacing( -1, 5); | 24 | layout->insertSpacing( -1, 5); |
25 | layout->insertWidget(-1, view); | 25 | layout->insertWidget(-1, view); |
26 | layout->insertSpacing(-1, 5); | 26 | layout->insertSpacing(-1, 5); |
27 | } \ No newline at end of file | 27 | } \ No newline at end of file |
diff --git a/noncore/tools/remote/helptab.h b/noncore/tools/remote/helptab.h index f3f99b3..83f24ef 100644 --- a/noncore/tools/remote/helptab.h +++ b/noncore/tools/remote/helptab.h | |||
@@ -1,26 +1,31 @@ | |||
1 | /* | 1 | /* |
2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. | 2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. |
3 | Copyright (C) 2002 Thomas Stephens | 3 | Copyright (C) 2002 Thomas Stephens |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public | 5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public |
6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later | 6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later |
7 | version. | 7 | version. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | 9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | 10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11 | Public License for more details. | 11 | Public License for more details. |
12 | 12 | ||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | 13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free |
14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #ifndef HELP_TAB_H | ||
18 | #define HELP_TAB_H | ||
19 | |||
17 | #include <qwidget.h> | 20 | #include <qwidget.h> |
18 | #include <qtextview.h> | 21 | #include <qtextview.h> |
19 | #include <qstring.h> | 22 | #include <qstring.h> |
20 | #include <qlayout.h> | 23 | #include <qlayout.h> |
21 | 24 | ||
22 | class HelpTab : public QWidget | 25 | class HelpTab : public QWidget |
23 | { | 26 | { |
24 | public: | 27 | public: |
25 | HelpTab(QWidget *parent=0, const char *name=0); | 28 | HelpTab(QWidget *parent=0, const char *name=0); |
26 | }; \ No newline at end of file | 29 | }; |
30 | |||
31 | #endif | ||
diff --git a/noncore/tools/remote/recorddialog.cpp b/noncore/tools/remote/recorddialog.cpp index f7cd30c..cfab730 100644 --- a/noncore/tools/remote/recorddialog.cpp +++ b/noncore/tools/remote/recorddialog.cpp | |||
@@ -1,81 +1,82 @@ | |||
1 | /* | 1 | /* |
2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. | 2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. |
3 | Copyright (C) 2002 Thomas Stephens | 3 | Copyright (C) 2002 Thomas Stephens |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public | 5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public |
6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later | 6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later |
7 | version. | 7 | version. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | 9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | 10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11 | Public License for more details. | 11 | Public License for more details. |
12 | 12 | ||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | 13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free |
14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "recorddialog.h" | 17 | #include "recorddialog.h" |
18 | 18 | ||
19 | RecordDialog::RecordDialog(QWidget *parent=0, const char *name=0):QDialog(parent, name) | 19 | RecordDialog::RecordDialog(QWidget *parent, const char *name) |
20 | :QDialog(parent, name) | ||
20 | { | 21 | { |
21 | QVBoxLayout *layout = new QVBoxLayout(this); | 22 | QVBoxLayout *layout = new QVBoxLayout(this); |
22 | QHBoxLayout *hlayout = new QHBoxLayout(this); | 23 | QHBoxLayout *hlayout = new QHBoxLayout(this); |
23 | 24 | ||
24 | layout->insertSpacing(0,5); | 25 | layout->insertSpacing(0,5); |
25 | output = new QTextView("Please enter the name of the new remote, and press Return\n", 0, this, "output"); | 26 | output = new QTextView("Please enter the name of the new remote, and press Return\n", 0, this, "output"); |
26 | layout->insertWidget(-1, output); | 27 | layout->insertWidget(-1, output); |
27 | layout->insertSpacing(-1, 5); | 28 | layout->insertSpacing(-1, 5); |
28 | layout->insertLayout(-1, hlayout); | 29 | layout->insertLayout(-1, hlayout); |
29 | layout->insertSpacing(-1, 5); | 30 | layout->insertSpacing(-1, 5); |
30 | 31 | ||
31 | hlayout->insertSpacing(0, 5); | 32 | hlayout->insertSpacing(0, 5); |
32 | input = new QLineEdit(this, "input"); | 33 | input = new QLineEdit(this, "input"); |
33 | hlayout->insertWidget(-1, input, 1); | 34 | hlayout->insertWidget(-1, input, 1); |
34 | hlayout->insertSpacing(-1, 5); | 35 | hlayout->insertSpacing(-1, 5); |
35 | 36 | ||
36 | QPushButton *ret = new QPushButton("Return", this, "return"); | 37 | QPushButton *ret = new QPushButton("Return", this, "return"); |
37 | hlayout->insertWidget(-1, ret); | 38 | hlayout->insertWidget(-1, ret); |
38 | hlayout->insertSpacing(-1, 5); | 39 | hlayout->insertSpacing(-1, 5); |
39 | connect(ret, SIGNAL(clicked()), this, SLOT(retPressed()) ); | 40 | connect(ret, SIGNAL(clicked()), this, SLOT(retPressed()) ); |
40 | where = 0; | 41 | where = 0; |
41 | 42 | ||
42 | record = new OProcess; | 43 | record = new OProcess; |
43 | } | 44 | } |
44 | 45 | ||
45 | void RecordDialog::retPressed() | 46 | void RecordDialog::retPressed() |
46 | { | 47 | { |
47 | printf("RecordDialog::retPressed: ret pressed\n"); | 48 | printf("RecordDialog::retPressed: ret pressed\n"); |
48 | 49 | ||
49 | if(where == 0) | 50 | if(where == 0) |
50 | { | 51 | { |
51 | connect(record, SIGNAL(receivedStdout(OProcess *, char *, int)), this, SLOT(incoming(OProcess *, char *, int)) ); | 52 | connect(record, SIGNAL(receivedStdout(OProcess *, char *, int)), this, SLOT(incoming(OProcess *, char *, int)) ); |
52 | connect(record, SIGNAL(receivedStderr(OProcess *, char *, int)), this, SLOT(incoming(OProcess *, char *, int)) ); | 53 | connect(record, SIGNAL(receivedStderr(OProcess *, char *, int)), this, SLOT(incoming(OProcess *, char *, int)) ); |
53 | connect(record, SIGNAL(processExited(OProcess *)), this, SLOT(done(OProcess *)) ); | 54 | connect(record, SIGNAL(processExited(OProcess *)), this, SLOT(done(OProcess *)) ); |
54 | printf("RecordDialog::retPressed: starting irrecord\n"); | 55 | printf("RecordDialog::retPressed: starting irrecord\n"); |
55 | QString file = "/tmp/" + input->text(); | 56 | QString file = "/tmp/" + input->text(); |
56 | *record<<"irrecord"<<file.latin1(); | 57 | *record<<"irrecord"<<file.latin1(); |
57 | if(!record->start(OProcess::NotifyOnExit, OProcess::AllOutput)) | 58 | if(!record->start(OProcess::NotifyOnExit, OProcess::AllOutput)) |
58 | { | 59 | { |
59 | QMessageBox *mb = new QMessageBox("Error!", | 60 | QMessageBox *mb = new QMessageBox("Error!", |
60 | "Could not start irrecord. You must<br>use an lirc ipkg that includes<br>irrecord", | 61 | "Could not start irrecord. You must<br>use an lirc ipkg that includes<br>irrecord", |
61 | QMessageBox::NoIcon, | 62 | QMessageBox::NoIcon, |
62 | QMessageBox::Ok, | 63 | QMessageBox::Ok, |
63 | QMessageBox::NoButton, | 64 | QMessageBox::NoButton, |
64 | QMessageBox::NoButton); | 65 | QMessageBox::NoButton); |
65 | mb->exec(); | 66 | mb->exec(); |
66 | return; | 67 | return; |
67 | } | 68 | } |
68 | // record->resume(); | 69 | // record->resume(); |
69 | where = 1; | 70 | where = 1; |
70 | } | 71 | } |
71 | } | 72 | } |
72 | 73 | ||
73 | void RecordDialog::incoming(OProcess *proc, char *buffer, int len) | 74 | void RecordDialog::incoming(OProcess *proc, char *buffer, int len) |
74 | { | 75 | { |
75 | //output->setText(output->text() + QString(buffer).truncate(len-1)); | 76 | //output->setText(output->text() + QString(buffer).truncate(len-1)); |
76 | printf("RecordDialog::incoming: got text from irrecord\n"); | 77 | printf("RecordDialog::incoming: got text from irrecord\n"); |
77 | } | 78 | } |
78 | 79 | ||
79 | void RecordDialog::done(OProcess *proc) | 80 | void RecordDialog::done(OProcess *proc) |
80 | { | 81 | { |
81 | } | 82 | } |
diff --git a/noncore/tools/remote/recorddialog.h b/noncore/tools/remote/recorddialog.h index 38b2bb4..e4dcae6 100644 --- a/noncore/tools/remote/recorddialog.h +++ b/noncore/tools/remote/recorddialog.h | |||
@@ -1,43 +1,49 @@ | |||
1 | /* | 1 | /* |
2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. | 2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. |
3 | Copyright (C) 2002 Thomas Stephens | 3 | Copyright (C) 2002 Thomas Stephens |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public | 5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public |
6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later | 6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later |
7 | version. | 7 | version. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | 9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | 10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11 | Public License for more details. | 11 | Public License for more details. |
12 | 12 | ||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | 13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free |
14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #ifndef RecordDialog_H | ||
18 | #define RecordDialog_H | ||
19 | |||
17 | #include <qdialog.h> | 20 | #include <qdialog.h> |
18 | #include <qtextview.h> | 21 | #include <qtextview.h> |
19 | #include <qlineedit.h> | 22 | #include <qlineedit.h> |
20 | #include <qpushbutton.h> | 23 | #include <qpushbutton.h> |
21 | #include <qwidget.h> | 24 | #include <qwidget.h> |
22 | #include <qlayout.h> | 25 | #include <qlayout.h> |
23 | #include <qmessagebox.h> | 26 | #include <qmessagebox.h> |
24 | 27 | ||
25 | #include <stdio.h> | 28 | #include <stdio.h> |
26 | 29 | ||
27 | #include <opie/oprocess.h> | 30 | #include <opie/oprocess.h> |
28 | 31 | ||
29 | class RecordDialog : public QDialog | 32 | class RecordDialog : public QDialog |
30 | { | 33 | { |
31 | Q_OBJECT | 34 | Q_OBJECT |
32 | public: | 35 | public: |
33 | RecordDialog(QWidget *parent=0, const char *name=0); | 36 | RecordDialog(QWidget *parent=0, const char *name=0); |
34 | public slots: | 37 | public slots: |
35 | void retPressed(); | 38 | void retPressed(); |
36 | void incoming(OProcess *proc, char *buffer, int len); | 39 | void incoming(OProcess *proc, char *buffer, int len); |
37 | void done(OProcess *proc); | 40 | void done(OProcess *proc); |
38 | private: | 41 | private: |
39 | QTextView *output; | 42 | QTextView *output; |
40 | QLineEdit *input; | 43 | QLineEdit *input; |
41 | OProcess *record; | 44 | OProcess *record; |
42 | int where; | 45 | int where; |
43 | }; \ No newline at end of file | 46 | }; |
47 | |||
48 | #endif | ||
49 | |||