author | thufir <thufir> | 2002-07-04 17:21:16 (UTC) |
---|---|---|
committer | thufir <thufir> | 2002-07-04 17:21:16 (UTC) |
commit | 3fc06dce797f62393bab41f4ea520bdbeb31eb9f (patch) (unidiff) | |
tree | dfd314d2c9a2241f3dce5649592808ff1ee4aea0 | |
parent | baf06586f452ea77f773df038aba5635f57d96b8 (diff) | |
download | opie-3fc06dce797f62393bab41f4ea520bdbeb31eb9f.zip opie-3fc06dce797f62393bab41f4ea520bdbeb31eb9f.tar.gz opie-3fc06dce797f62393bab41f4ea520bdbeb31eb9f.tar.bz2 |
added license headers to opie-sheet
-rw-r--r-- | noncore/apps/opie-sheet/cellformat.cpp | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/cellformat.h | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/finddlg.cpp | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/finddlg.h | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/main.cpp | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/mainwindow.cpp | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/mainwindow.h | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/numberdlg.cpp | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/numberdlg.h | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sheet.cpp | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sheet.h | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sortdlg.cpp | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sortdlg.h | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/textdlg.cpp | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/textdlg.h | 14 |
15 files changed, 210 insertions, 0 deletions
diff --git a/noncore/apps/opie-sheet/cellformat.cpp b/noncore/apps/opie-sheet/cellformat.cpp index 6a2ff72..597502c 100644 --- a/noncore/apps/opie-sheet/cellformat.cpp +++ b/noncore/apps/opie-sheet/cellformat.cpp | |||
@@ -1,585 +1,599 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #include "cellformat.h" | 15 | #include "cellformat.h" |
2 | 16 | ||
3 | #include <qlistbox.h> | 17 | #include <qlistbox.h> |
4 | #include <qlabel.h> | 18 | #include <qlabel.h> |
5 | 19 | ||
6 | #define COMBO_WIDTHS 155 | 20 | #define COMBO_WIDTHS 155 |
7 | #define COMBO_HEIGHTS 21 | 21 | #define COMBO_HEIGHTS 21 |
8 | 22 | ||
9 | #define COLOR_COUNT 17 | 23 | #define COLOR_COUNT 17 |
10 | #define STYLE_COUNT 14 | 24 | #define STYLE_COUNT 14 |
11 | #define HALIGN_COUNT 3 | 25 | #define HALIGN_COUNT 3 |
12 | #define VALIGN_COUNT 3 | 26 | #define VALIGN_COUNT 3 |
13 | 27 | ||
14 | 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, 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}; |
15 | 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::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}; |
16 | QString namesHAlign[HALIGN_COUNT]={"Left", "Right", "Center"}; | 30 | QString namesHAlign[HALIGN_COUNT]={"Left", "Right", "Center"}; |
17 | QString namesVAlign[VALIGN_COUNT]={"Top", "Bottom", "Center"}; | 31 | QString namesVAlign[VALIGN_COUNT]={"Top", "Bottom", "Center"}; |
18 | Qt::AlignmentFlags flagsHAlign[HALIGN_COUNT]={Qt::AlignLeft, Qt::AlignRight, Qt::AlignHCenter}; | 32 | Qt::AlignmentFlags flagsHAlign[HALIGN_COUNT]={Qt::AlignLeft, Qt::AlignRight, Qt::AlignHCenter}; |
19 | Qt::AlignmentFlags flagsVAlign[VALIGN_COUNT]={Qt::AlignTop, Qt::AlignBottom, Qt::AlignVCenter}; | 33 | Qt::AlignmentFlags flagsVAlign[VALIGN_COUNT]={Qt::AlignTop, Qt::AlignBottom, Qt::AlignVCenter}; |
20 | 34 | ||
21 | CellFormat::CellFormat(QWidget *parent=0) | 35 | CellFormat::CellFormat(QWidget *parent=0) |
22 | :QDialog(parent, 0, TRUE) | 36 | :QDialog(parent, 0, TRUE) |
23 | { | 37 | { |
24 | // Main widget | 38 | // Main widget |
25 | tabs=new QTabWidget(this); | 39 | tabs=new QTabWidget(this); |
26 | widgetBorders=new QWidget(tabs); | 40 | widgetBorders=new QWidget(tabs); |
27 | widgetBackground=new QWidget(tabs); | 41 | widgetBackground=new QWidget(tabs); |
28 | widgetFont=new QWidget(tabs); | 42 | widgetFont=new QWidget(tabs); |
29 | widgetAlignment=new QWidget(tabs); | 43 | widgetAlignment=new QWidget(tabs); |
30 | tabs->addTab(widgetBorders, tr("&Borders")); | 44 | tabs->addTab(widgetBorders, tr("&Borders")); |
31 | tabs->addTab(widgetBackground, tr("Back&ground")); | 45 | tabs->addTab(widgetBackground, tr("Back&ground")); |
32 | tabs->addTab(widgetFont, tr("&Font")); | 46 | tabs->addTab(widgetFont, tr("&Font")); |
33 | tabs->addTab(widgetAlignment, tr("&Alignment")); | 47 | tabs->addTab(widgetAlignment, tr("&Alignment")); |
34 | 48 | ||
35 | fontDB.loadRenderers(); | 49 | fontDB.loadRenderers(); |
36 | changedFont=changedAlign=changedBrush=FALSE; | 50 | changedFont=changedAlign=changedBrush=FALSE; |
37 | 51 | ||
38 | // Borders tab | 52 | // Borders tab |
39 | borderEditor=new BorderEditor(widgetBorders); | 53 | borderEditor=new BorderEditor(widgetBorders); |
40 | borderEditor->setGeometry(10, 10, 215, 145); | 54 | borderEditor->setGeometry(10, 10, 215, 145); |
41 | connect(borderEditor, SIGNAL(clicked(BorderEditor::BorderArea)), this, SLOT(borderClicked(BorderEditor::BorderArea))); | 55 | connect(borderEditor, SIGNAL(clicked(BorderEditor::BorderArea)), this, SLOT(borderClicked(BorderEditor::BorderArea))); |
42 | 56 | ||
43 | comboBordersWidth=createCombo(COMBO_WIDTH, widgetBorders, tr("&Width:"), 165); | 57 | comboBordersWidth=createCombo(COMBO_WIDTH, widgetBorders, tr("&Width:"), 165); |
44 | comboBordersColor=createCombo(COMBO_COLOR, widgetBorders, tr("&Color:"), 165+(COMBO_HEIGHTS+10)); | 58 | comboBordersColor=createCombo(COMBO_COLOR, widgetBorders, tr("&Color:"), 165+(COMBO_HEIGHTS+10)); |
45 | 59 | ||
46 | buttonBordersDefaults=new QPushButton(tr("&Default Borders"), widgetBorders); | 60 | buttonBordersDefaults=new QPushButton(tr("&Default Borders"), widgetBorders); |
47 | buttonBordersDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); | 61 | buttonBordersDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); |
48 | connect(buttonBordersDefaults, SIGNAL(clicked()), this, SLOT(slotBordersDefaults())); | 62 | connect(buttonBordersDefaults, SIGNAL(clicked()), this, SLOT(slotBordersDefaults())); |
49 | 63 | ||
50 | // Background tab | 64 | // Background tab |
51 | frameBackground=new QFrame(widgetBackground); | 65 | frameBackground=new QFrame(widgetBackground); |
52 | frameBackground->setGeometry(10, 10, 215, 145); | 66 | frameBackground->setGeometry(10, 10, 215, 145); |
53 | frameBackground->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); | 67 | frameBackground->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); |
54 | 68 | ||
55 | comboBackgroundStyle=createCombo(COMBO_STYLE, widgetBackground, tr("&Style:"), 165); | 69 | comboBackgroundStyle=createCombo(COMBO_STYLE, widgetBackground, tr("&Style:"), 165); |
56 | connect(comboBackgroundStyle, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int))); | 70 | connect(comboBackgroundStyle, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int))); |
57 | comboBackgroundColor=createCombo(COMBO_COLOR, widgetBackground, tr("&Color:"), 165+(COMBO_HEIGHTS+10)); | 71 | comboBackgroundColor=createCombo(COMBO_COLOR, widgetBackground, tr("&Color:"), 165+(COMBO_HEIGHTS+10)); |
58 | connect(comboBackgroundColor, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int))); | 72 | connect(comboBackgroundColor, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int))); |
59 | 73 | ||
60 | buttonBackgroundDefaults=new QPushButton(tr("&Default Background"), widgetBackground); | 74 | buttonBackgroundDefaults=new QPushButton(tr("&Default Background"), widgetBackground); |
61 | buttonBackgroundDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); | 75 | buttonBackgroundDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); |
62 | connect(buttonBackgroundDefaults, SIGNAL(clicked()), this, SLOT(slotBackgroundDefaults())); | 76 | connect(buttonBackgroundDefaults, SIGNAL(clicked()), this, SLOT(slotBackgroundDefaults())); |
63 | 77 | ||
64 | // Font tab | 78 | // Font tab |
65 | frameFont=new QFrame(widgetFont); | 79 | frameFont=new QFrame(widgetFont); |
66 | frameFont->setGeometry(10, 10, 215, 125); | 80 | frameFont->setGeometry(10, 10, 215, 125); |
67 | frameFont->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); | 81 | frameFont->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); |
68 | 82 | ||
69 | comboFontFamily=createCombo(COMBO_FONT, widgetFont, tr("&Font:"), 145); | 83 | comboFontFamily=createCombo(COMBO_FONT, widgetFont, tr("&Font:"), 145); |
70 | connect(comboFontFamily, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); | 84 | connect(comboFontFamily, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); |
71 | comboFontSize=createCombo(COMBO_SIZE, widgetFont, tr("&Size:"), 145+(COMBO_HEIGHTS+10)); | 85 | comboFontSize=createCombo(COMBO_SIZE, widgetFont, tr("&Size:"), 145+(COMBO_HEIGHTS+10)); |
72 | connect(comboFontSize, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); | 86 | connect(comboFontSize, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); |
73 | comboFontColor=createCombo(COMBO_COLOR, widgetFont, tr("&Color:"), 145+2*(COMBO_HEIGHTS+10)); | 87 | comboFontColor=createCombo(COMBO_COLOR, widgetFont, tr("&Color:"), 145+2*(COMBO_HEIGHTS+10)); |
74 | connect(comboFontColor, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); | 88 | connect(comboFontColor, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); |
75 | 89 | ||
76 | checkFontBold=new QCheckBox(tr("&Bold"), widgetFont); | 90 | checkFontBold=new QCheckBox(tr("&Bold"), widgetFont); |
77 | checkFontBold->setGeometry(10, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS); | 91 | checkFontBold->setGeometry(10, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS); |
78 | connect(checkFontBold, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool))); | 92 | connect(checkFontBold, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool))); |
79 | checkFontItalic=new QCheckBox(tr("&Italic"), widgetFont); | 93 | checkFontItalic=new QCheckBox(tr("&Italic"), widgetFont); |
80 | checkFontItalic->setGeometry(60, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS); | 94 | checkFontItalic->setGeometry(60, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS); |
81 | connect(checkFontItalic, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool))); | 95 | connect(checkFontItalic, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool))); |
82 | 96 | ||
83 | buttonFontDefaults=new QPushButton(tr("&Default Font"), widgetFont); | 97 | buttonFontDefaults=new QPushButton(tr("&Default Font"), widgetFont); |
84 | buttonFontDefaults->setGeometry(115, 145+3*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); | 98 | buttonFontDefaults->setGeometry(115, 145+3*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); |
85 | connect(buttonFontDefaults, SIGNAL(clicked()), this, SLOT(slotFontDefaults())); | 99 | connect(buttonFontDefaults, SIGNAL(clicked()), this, SLOT(slotFontDefaults())); |
86 | 100 | ||
87 | // Alignment tab | 101 | // Alignment tab |
88 | frameAlignment=new QFrame(widgetAlignment); | 102 | frameAlignment=new QFrame(widgetAlignment); |
89 | frameAlignment->setGeometry(10, 10, 215, 145); | 103 | frameAlignment->setGeometry(10, 10, 215, 145); |
90 | frameAlignment->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); | 104 | frameAlignment->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); |
91 | 105 | ||
92 | comboAlignmentVertical=createCombo(COMBO_VALIGN, widgetAlignment, tr("&Vertical:"), 165); | 106 | comboAlignmentVertical=createCombo(COMBO_VALIGN, widgetAlignment, tr("&Vertical:"), 165); |
93 | connect(comboAlignmentVertical, SIGNAL(activated(int)), this, SLOT(alignClicked(int))); | 107 | connect(comboAlignmentVertical, SIGNAL(activated(int)), this, SLOT(alignClicked(int))); |
94 | comboAlignmentHorizontal=createCombo(COMBO_HALIGN, widgetAlignment, tr("&Horizontal:"), 165+(COMBO_HEIGHTS+10)); | 108 | comboAlignmentHorizontal=createCombo(COMBO_HALIGN, widgetAlignment, tr("&Horizontal:"), 165+(COMBO_HEIGHTS+10)); |
95 | connect(comboAlignmentHorizontal, SIGNAL(activated(int)), this, SLOT(alignClicked(int))); | 109 | connect(comboAlignmentHorizontal, SIGNAL(activated(int)), this, SLOT(alignClicked(int))); |
96 | 110 | ||
97 | checkAlignmentWrap=new QCheckBox(tr("&Word Wrap"), widgetAlignment); | 111 | checkAlignmentWrap=new QCheckBox(tr("&Word Wrap"), widgetAlignment); |
98 | checkAlignmentWrap->setGeometry(10, 165+2*(COMBO_HEIGHTS+10), 90, COMBO_HEIGHTS); | 112 | checkAlignmentWrap->setGeometry(10, 165+2*(COMBO_HEIGHTS+10), 90, COMBO_HEIGHTS); |
99 | connect(checkAlignmentWrap, SIGNAL(toggled(bool)), this, SLOT(alignClicked(bool))); | 113 | connect(checkAlignmentWrap, SIGNAL(toggled(bool)), this, SLOT(alignClicked(bool))); |
100 | 114 | ||
101 | buttonAlignmentDefaults=new QPushButton(tr("&Default Alignment"), widgetAlignment); | 115 | buttonAlignmentDefaults=new QPushButton(tr("&Default Alignment"), widgetAlignment); |
102 | buttonAlignmentDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); | 116 | buttonAlignmentDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); |
103 | connect(buttonAlignmentDefaults, SIGNAL(clicked()), this, SLOT(slotAlignmentDefaults())); | 117 | connect(buttonAlignmentDefaults, SIGNAL(clicked()), this, SLOT(slotAlignmentDefaults())); |
104 | 118 | ||
105 | // Main widget | 119 | // Main widget |
106 | box=new QVBoxLayout(this); | 120 | box=new QVBoxLayout(this); |
107 | box->addWidget(tabs); | 121 | box->addWidget(tabs); |
108 | 122 | ||
109 | setCaption(tr("Format Cells")); | 123 | setCaption(tr("Format Cells")); |
110 | } | 124 | } |
111 | 125 | ||
112 | CellFormat::~CellFormat() | 126 | CellFormat::~CellFormat() |
113 | { | 127 | { |
114 | } | 128 | } |
115 | 129 | ||
116 | int CellFormat::findColorIndex(const QColor &color) | 130 | int CellFormat::findColorIndex(const QColor &color) |
117 | { | 131 | { |
118 | for (int i=0; i<COLOR_COUNT; ++i) | 132 | for (int i=0; i<COLOR_COUNT; ++i) |
119 | if (qtColors[i]==color) | 133 | if (qtColors[i]==color) |
120 | return i; | 134 | return i; |
121 | return 0; | 135 | return 0; |
122 | } | 136 | } |
123 | 137 | ||
124 | int CellFormat::findVAlignIndex(Qt::AlignmentFlags flag) | 138 | int CellFormat::findVAlignIndex(Qt::AlignmentFlags flag) |
125 | { | 139 | { |
126 | for (int i=0; i<VALIGN_COUNT; ++i) | 140 | for (int i=0; i<VALIGN_COUNT; ++i) |
127 | if (flagsVAlign[i] & flag) | 141 | if (flagsVAlign[i] & flag) |
128 | return i; | 142 | return i; |
129 | return 0; | 143 | return 0; |
130 | } | 144 | } |
131 | 145 | ||
132 | int CellFormat::findHAlignIndex(Qt::AlignmentFlags flag) | 146 | int CellFormat::findHAlignIndex(Qt::AlignmentFlags flag) |
133 | { | 147 | { |
134 | for (int i=0; i<HALIGN_COUNT; ++i) | 148 | for (int i=0; i<HALIGN_COUNT; ++i) |
135 | if (flagsHAlign[i] & flag) | 149 | if (flagsHAlign[i] & flag) |
136 | return i; | 150 | return i; |
137 | return 0; | 151 | return 0; |
138 | } | 152 | } |
139 | 153 | ||
140 | int CellFormat::findBrushStyleIndex(Qt::BrushStyle style) | 154 | int CellFormat::findBrushStyleIndex(Qt::BrushStyle style) |
141 | { | 155 | { |
142 | for (int i=0; i<STYLE_COUNT; ++i) | 156 | for (int i=0; i<STYLE_COUNT; ++i) |
143 | if (brushStyles[i]==style) | 157 | if (brushStyles[i]==style) |
144 | return i; | 158 | return i; |
145 | return 0; | 159 | return 0; |
146 | } | 160 | } |
147 | 161 | ||
148 | void CellFormat::setBrushBackground(const QBrush &brush) | 162 | void CellFormat::setBrushBackground(const QBrush &brush) |
149 | { | 163 | { |
150 | comboBackgroundColor->setCurrentItem(findColorIndex(brush.color())); | 164 | comboBackgroundColor->setCurrentItem(findColorIndex(brush.color())); |
151 | comboBackgroundStyle->setCurrentItem(findBrushStyleIndex(brush.style())); | 165 | comboBackgroundStyle->setCurrentItem(findBrushStyleIndex(brush.style())); |
152 | 166 | ||
153 | QPixmap pix(frameBackground->contentsRect().width(), frameBackground->contentsRect().height()); | 167 | QPixmap pix(frameBackground->contentsRect().width(), frameBackground->contentsRect().height()); |
154 | QPainter p(&pix); | 168 | QPainter p(&pix); |
155 | pix.fill(); | 169 | pix.fill(); |
156 | p.fillRect(pix.rect(), brush); | 170 | p.fillRect(pix.rect(), brush); |
157 | frameBackground->setBackgroundPixmap(pix); | 171 | frameBackground->setBackgroundPixmap(pix); |
158 | 172 | ||
159 | brushBackground=brush; | 173 | brushBackground=brush; |
160 | } | 174 | } |
161 | 175 | ||
162 | void CellFormat::setTextFont(const QFont &font, const QColor &color) | 176 | void CellFormat::setTextFont(const QFont &font, const QColor &color) |
163 | { | 177 | { |
164 | comboFontColor->setCurrentItem(findColorIndex(color)); | 178 | comboFontColor->setCurrentItem(findColorIndex(color)); |
165 | comboFontFamily->setCurrentItem(findComboItemIndex(comboFontFamily, font.family())); | 179 | comboFontFamily->setCurrentItem(findComboItemIndex(comboFontFamily, font.family())); |
166 | comboFontSize->setCurrentItem(findComboItemIndex(comboFontSize, QString::number(font.pointSize()))); | 180 | comboFontSize->setCurrentItem(findComboItemIndex(comboFontSize, QString::number(font.pointSize()))); |
167 | checkFontBold->setChecked(font.weight()==QFont::Bold); | 181 | checkFontBold->setChecked(font.weight()==QFont::Bold); |
168 | checkFontItalic->setChecked(font.italic()); | 182 | checkFontItalic->setChecked(font.italic()); |
169 | 183 | ||
170 | QPixmap pix(frameFont->contentsRect().width(), frameFont->contentsRect().height()); | 184 | QPixmap pix(frameFont->contentsRect().width(), frameFont->contentsRect().height()); |
171 | QPainter p(&pix); | 185 | QPainter p(&pix); |
172 | pix.fill(); | 186 | pix.fill(); |
173 | p.fillRect(pix.rect(), Qt::white); | 187 | p.fillRect(pix.rect(), Qt::white); |
174 | p.setFont(font); | 188 | p.setFont(font); |
175 | p.setPen(color); | 189 | p.setPen(color); |
176 | p.drawText(pix.rect(), Qt::AlignCenter, tr("Opie Sheet")); | 190 | p.drawText(pix.rect(), Qt::AlignCenter, tr("Opie Sheet")); |
177 | frameFont->setBackgroundPixmap(pix); | 191 | frameFont->setBackgroundPixmap(pix); |
178 | 192 | ||
179 | fontFont=font; | 193 | fontFont=font; |
180 | fontColor=color; | 194 | fontColor=color; |
181 | } | 195 | } |
182 | 196 | ||
183 | void CellFormat::setTextAlign(Qt::AlignmentFlags flags) | 197 | void CellFormat::setTextAlign(Qt::AlignmentFlags flags) |
184 | { | 198 | { |
185 | comboAlignmentVertical->setCurrentItem(findVAlignIndex(flags)); | 199 | comboAlignmentVertical->setCurrentItem(findVAlignIndex(flags)); |
186 | comboAlignmentHorizontal->setCurrentItem(findHAlignIndex(flags)); | 200 | comboAlignmentHorizontal->setCurrentItem(findHAlignIndex(flags)); |
187 | checkAlignmentWrap->setChecked(flags & Qt::WordBreak); | 201 | checkAlignmentWrap->setChecked(flags & Qt::WordBreak); |
188 | 202 | ||
189 | QPixmap pix(frameAlignment->contentsRect().width(), frameAlignment->contentsRect().height()); | 203 | QPixmap pix(frameAlignment->contentsRect().width(), frameAlignment->contentsRect().height()); |
190 | QPainter p(&pix); | 204 | QPainter p(&pix); |
191 | pix.fill(); | 205 | pix.fill(); |
192 | p.fillRect(pix.rect(), Qt::white); | 206 | p.fillRect(pix.rect(), Qt::white); |
193 | p.drawText(10, 10, pix.width()-20, pix.height()-20, flags, tr("Opie Sheet")); | 207 | p.drawText(10, 10, pix.width()-20, pix.height()-20, flags, tr("Opie Sheet")); |
194 | frameAlignment->setBackgroundPixmap(pix); | 208 | frameAlignment->setBackgroundPixmap(pix); |
195 | 209 | ||
196 | textAlignment=flags; | 210 | textAlignment=flags; |
197 | } | 211 | } |
198 | 212 | ||
199 | void CellFormat::slotFontDefaults() | 213 | void CellFormat::slotFontDefaults() |
200 | { | 214 | { |
201 | changedFont=TRUE; | 215 | changedFont=TRUE; |
202 | setTextFont(font(), Qt::black); | 216 | setTextFont(font(), Qt::black); |
203 | } | 217 | } |
204 | 218 | ||
205 | void CellFormat::slotAlignmentDefaults() | 219 | void CellFormat::slotAlignmentDefaults() |
206 | { | 220 | { |
207 | changedAlign=TRUE; | 221 | changedAlign=TRUE; |
208 | setTextAlign((Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop)); | 222 | setTextAlign((Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop)); |
209 | } | 223 | } |
210 | 224 | ||
211 | void CellFormat::slotBackgroundDefaults() | 225 | void CellFormat::slotBackgroundDefaults() |
212 | { | 226 | { |
213 | changedBrush=TRUE; | 227 | changedBrush=TRUE; |
214 | setBrushBackground(Qt::white); | 228 | setBrushBackground(Qt::white); |
215 | } | 229 | } |
216 | 230 | ||
217 | void CellFormat::slotBordersDefaults() | 231 | void CellFormat::slotBordersDefaults() |
218 | { | 232 | { |
219 | QPen defaultPen(Qt::gray, 1, Qt::SolidLine); | 233 | QPen defaultPen(Qt::gray, 1, Qt::SolidLine); |
220 | borderEditor->setPen(defaultPen, BorderEditor::Top); | 234 | borderEditor->setPen(defaultPen, BorderEditor::Top); |
221 | borderEditor->setPen(defaultPen, BorderEditor::Bottom); | 235 | borderEditor->setPen(defaultPen, BorderEditor::Bottom); |
222 | borderEditor->setPen(defaultPen, BorderEditor::Left); | 236 | borderEditor->setPen(defaultPen, BorderEditor::Left); |
223 | borderEditor->setPen(defaultPen, BorderEditor::Right); | 237 | borderEditor->setPen(defaultPen, BorderEditor::Right); |
224 | borderEditor->setPen(defaultPen, BorderEditor::Vert); | 238 | borderEditor->setPen(defaultPen, BorderEditor::Vert); |
225 | borderEditor->setPen(defaultPen, BorderEditor::Horz); | 239 | borderEditor->setPen(defaultPen, BorderEditor::Horz); |
226 | } | 240 | } |
227 | 241 | ||
228 | void CellFormat::backgroundClicked(int index) | 242 | void CellFormat::backgroundClicked(int index) |
229 | { | 243 | { |
230 | changedBrush=TRUE; | 244 | changedBrush=TRUE; |
231 | setBrushBackground(QBrush(qtColors[comboBackgroundColor->currentItem()], brushStyles[comboBackgroundStyle->currentItem()])); | 245 | setBrushBackground(QBrush(qtColors[comboBackgroundColor->currentItem()], brushStyles[comboBackgroundStyle->currentItem()])); |
232 | } | 246 | } |
233 | 247 | ||
234 | void CellFormat::fontClicked(bool on) | 248 | void CellFormat::fontClicked(bool on) |
235 | { | 249 | { |
236 | fontClicked(0); | 250 | fontClicked(0); |
237 | } | 251 | } |
238 | 252 | ||
239 | void CellFormat::fontClicked(int index) | 253 | void CellFormat::fontClicked(int index) |
240 | { | 254 | { |
241 | changedFont=TRUE; | 255 | changedFont=TRUE; |
242 | setTextFont(QFont(comboFontFamily->currentText(), comboFontSize->currentText().toInt(), checkFontBold->isChecked() ? QFont::Bold : QFont::Normal, checkFontItalic->isChecked(), QFont::AnyCharSet), qtColors[comboFontColor->currentItem()]); | 256 | setTextFont(QFont(comboFontFamily->currentText(), comboFontSize->currentText().toInt(), checkFontBold->isChecked() ? QFont::Bold : QFont::Normal, checkFontItalic->isChecked(), QFont::AnyCharSet), qtColors[comboFontColor->currentItem()]); |
243 | } | 257 | } |
244 | 258 | ||
245 | void CellFormat::alignClicked(bool on) | 259 | void CellFormat::alignClicked(bool on) |
246 | { | 260 | { |
247 | alignClicked(0); | 261 | alignClicked(0); |
248 | } | 262 | } |
249 | 263 | ||
250 | void CellFormat::alignClicked(int index) | 264 | void CellFormat::alignClicked(int index) |
251 | { | 265 | { |
252 | changedAlign=TRUE; | 266 | changedAlign=TRUE; |
253 | setTextAlign((Qt::AlignmentFlags)(flagsVAlign[comboAlignmentVertical->currentItem()] | flagsHAlign[comboAlignmentHorizontal->currentItem()] | (checkAlignmentWrap->isChecked() ? Qt::WordBreak : 0))); | 267 | setTextAlign((Qt::AlignmentFlags)(flagsVAlign[comboAlignmentVertical->currentItem()] | flagsHAlign[comboAlignmentHorizontal->currentItem()] | (checkAlignmentWrap->isChecked() ? Qt::WordBreak : 0))); |
254 | } | 268 | } |
255 | 269 | ||
256 | void CellFormat::createSizeCombo(QComboBox *combo) | 270 | void CellFormat::createSizeCombo(QComboBox *combo) |
257 | { | 271 | { |
258 | combo->clear(); | 272 | combo->clear(); |
259 | QValueList<int> sizes=fontDB.standardSizes(); | 273 | QValueList<int> sizes=fontDB.standardSizes(); |
260 | for (QValueList<int>::ConstIterator i=sizes.begin(); i!=sizes.end(); ++i) | 274 | for (QValueList<int>::ConstIterator i=sizes.begin(); i!=sizes.end(); ++i) |
261 | combo->insertItem(QString::number(*i)); | 275 | combo->insertItem(QString::number(*i)); |
262 | } | 276 | } |
263 | 277 | ||
264 | void CellFormat::borderClicked(BorderEditor::BorderArea area) | 278 | void CellFormat::borderClicked(BorderEditor::BorderArea area) |
265 | { | 279 | { |
266 | QPen newPen(qtColors[comboBordersColor->currentItem()], comboBordersWidth->currentItem()+1, Qt::SolidLine); | 280 | QPen newPen(qtColors[comboBordersColor->currentItem()], comboBordersWidth->currentItem()+1, Qt::SolidLine); |
267 | if (newPen==borderEditor->getPen(area)) | 281 | if (newPen==borderEditor->getPen(area)) |
268 | borderEditor->setPen(QPen(Qt::gray, 1, Qt::NoPen), area); | 282 | borderEditor->setPen(QPen(Qt::gray, 1, Qt::NoPen), area); |
269 | else | 283 | else |
270 | borderEditor->setPen(newPen, area); | 284 | borderEditor->setPen(newPen, area); |
271 | } | 285 | } |
272 | 286 | ||
273 | int CellFormat::findComboItemIndex(QComboBox *combo, const QString &item) | 287 | int CellFormat::findComboItemIndex(QComboBox *combo, const QString &item) |
274 | { | 288 | { |
275 | for (int i=0; i<combo->count(); ++i) | 289 | for (int i=0; i<combo->count(); ++i) |
276 | if (combo->text(i)==item) | 290 | if (combo->text(i)==item) |
277 | return i; | 291 | return i; |
278 | return 0; | 292 | return 0; |
279 | } | 293 | } |
280 | 294 | ||
281 | QComboBox *CellFormat::createCombo(comboType type, QWidget *parent, const QString &caption, int y) | 295 | QComboBox *CellFormat::createCombo(comboType type, QWidget *parent, const QString &caption, int y) |
282 | { | 296 | { |
283 | QComboBox *combo=new QComboBox(FALSE, parent); | 297 | QComboBox *combo=new QComboBox(FALSE, parent); |
284 | combo->setGeometry(70, y, COMBO_WIDTHS, COMBO_HEIGHTS); | 298 | combo->setGeometry(70, y, COMBO_WIDTHS, COMBO_HEIGHTS); |
285 | combo->setSizeLimit(5); | 299 | combo->setSizeLimit(5); |
286 | 300 | ||
287 | switch (type) | 301 | switch (type) |
288 | { | 302 | { |
289 | case COMBO_WIDTH: createWidthCombo(combo); break; | 303 | case COMBO_WIDTH: createWidthCombo(combo); break; |
290 | case COMBO_STYLE: createStyleCombo(combo); break; | 304 | case COMBO_STYLE: createStyleCombo(combo); break; |
291 | case COMBO_FONT: createFontCombo(combo); break; | 305 | case COMBO_FONT: createFontCombo(combo); break; |
292 | case COMBO_SIZE: createSizeCombo(combo); break; | 306 | case COMBO_SIZE: createSizeCombo(combo); break; |
293 | case COMBO_COLOR: createColorCombo(combo); break; | 307 | case COMBO_COLOR: createColorCombo(combo); break; |
294 | case COMBO_HALIGN: createHAlignCombo(combo); break; | 308 | case COMBO_HALIGN: createHAlignCombo(combo); break; |
295 | case COMBO_VALIGN: createVAlignCombo(combo); break; | 309 | case COMBO_VALIGN: createVAlignCombo(combo); break; |
296 | } | 310 | } |
297 | 311 | ||
298 | QLabel *label=new QLabel(combo, caption, parent); | 312 | QLabel *label=new QLabel(combo, caption, parent); |
299 | label->setGeometry(10, y, 50, COMBO_HEIGHTS); | 313 | label->setGeometry(10, y, 50, COMBO_HEIGHTS); |
300 | 314 | ||
301 | return combo; | 315 | return combo; |
302 | } | 316 | } |
303 | 317 | ||
304 | void CellFormat::createHAlignCombo(QComboBox *combo) | 318 | void CellFormat::createHAlignCombo(QComboBox *combo) |
305 | { | 319 | { |
306 | for (int i=0; i<HALIGN_COUNT; ++i) | 320 | for (int i=0; i<HALIGN_COUNT; ++i) |
307 | combo->insertItem(namesHAlign[i]); | 321 | combo->insertItem(namesHAlign[i]); |
308 | } | 322 | } |
309 | 323 | ||
310 | void CellFormat::createVAlignCombo(QComboBox *combo) | 324 | void CellFormat::createVAlignCombo(QComboBox *combo) |
311 | { | 325 | { |
312 | for (int i=0; i<VALIGN_COUNT; ++i) | 326 | for (int i=0; i<VALIGN_COUNT; ++i) |
313 | combo->insertItem(namesVAlign[i]); | 327 | combo->insertItem(namesVAlign[i]); |
314 | } | 328 | } |
315 | 329 | ||
316 | void CellFormat::createWidthCombo(QComboBox *combo) | 330 | void CellFormat::createWidthCombo(QComboBox *combo) |
317 | { | 331 | { |
318 | int width=combo->listBox()->maxItemWidth(); | 332 | int width=combo->listBox()->maxItemWidth(); |
319 | QPixmap pix(width, COMBO_HEIGHTS); | 333 | QPixmap pix(width, COMBO_HEIGHTS); |
320 | QPainter p(&pix); | 334 | QPainter p(&pix); |
321 | 335 | ||
322 | for (int i=1; i<=6; ++i) | 336 | for (int i=1; i<=6; ++i) |
323 | { | 337 | { |
324 | pix.fill(); | 338 | pix.fill(); |
325 | p.setPen(QPen(Qt::black, i, Qt::SolidLine)); | 339 | p.setPen(QPen(Qt::black, i, Qt::SolidLine)); |
326 | p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2); | 340 | p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2); |
327 | combo->insertItem(pix); | 341 | combo->insertItem(pix); |
328 | } | 342 | } |
329 | } | 343 | } |
330 | 344 | ||
331 | void CellFormat::createFontCombo(QComboBox *combo) | 345 | void CellFormat::createFontCombo(QComboBox *combo) |
332 | { | 346 | { |
333 | combo->insertStringList(fontDB.families()); | 347 | combo->insertStringList(fontDB.families()); |
334 | } | 348 | } |
335 | 349 | ||
336 | void CellFormat::createStyleCombo(QComboBox *combo) | 350 | void CellFormat::createStyleCombo(QComboBox *combo) |
337 | { | 351 | { |
338 | int width=combo->listBox()->maxItemWidth(); | 352 | int width=combo->listBox()->maxItemWidth(); |
339 | QPixmap pix(width, COMBO_HEIGHTS); | 353 | QPixmap pix(width, COMBO_HEIGHTS); |
340 | QPainter p(&pix); | 354 | QPainter p(&pix); |
341 | 355 | ||
342 | for (int i=0; i<STYLE_COUNT; ++i) | 356 | for (int i=0; i<STYLE_COUNT; ++i) |
343 | { | 357 | { |
344 | pix.fill(); | 358 | pix.fill(); |
345 | p.fillRect(5, 5, width-10, COMBO_HEIGHTS-10, brushStyles[i]); | 359 | p.fillRect(5, 5, width-10, COMBO_HEIGHTS-10, brushStyles[i]); |
346 | combo->insertItem(pix); | 360 | combo->insertItem(pix); |
347 | } | 361 | } |
348 | } | 362 | } |
349 | 363 | ||
350 | void CellFormat::createColorCombo(QComboBox *combo) | 364 | void CellFormat::createColorCombo(QComboBox *combo) |
351 | { | 365 | { |
352 | int width=combo->listBox()->maxItemWidth(); | 366 | int width=combo->listBox()->maxItemWidth(); |
353 | QPixmap pix(width, COMBO_HEIGHTS); | 367 | QPixmap pix(width, COMBO_HEIGHTS); |
354 | QPainter p(&pix); | 368 | QPainter p(&pix); |
355 | 369 | ||
356 | for (int i=0; i<COLOR_COUNT; ++i) | 370 | for (int i=0; i<COLOR_COUNT; ++i) |
357 | { | 371 | { |
358 | pix.fill(); | 372 | pix.fill(); |
359 | p.setPen(QPen(qtColors[i], 3, Qt::SolidLine)); | 373 | p.setPen(QPen(qtColors[i], 3, Qt::SolidLine)); |
360 | p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2); | 374 | p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2); |
361 | combo->insertItem(pix); | 375 | combo->insertItem(pix); |
362 | } | 376 | } |
363 | } | 377 | } |
364 | 378 | ||
365 | int CellFormat::exec(Sheet *s) | 379 | int CellFormat::exec(Sheet *s) |
366 | { | 380 | { |
367 | sheet=s; | 381 | sheet=s; |
368 | int row1, row2, col1, col2, row, col; | 382 | int row1, row2, col1, col2, row, col; |
369 | sheet->getSelection(&row1, &col1, &row2, &col2); | 383 | sheet->getSelection(&row1, &col1, &row2, &col2); |
370 | 384 | ||
371 | QPen penTop=sheet->getPen(row1-1, col1, 0), penBottom=sheet->getPen(row2, col1, 0), | 385 | QPen penTop=sheet->getPen(row1-1, col1, 0), penBottom=sheet->getPen(row2, col1, 0), |
372 | penLeft=sheet->getPen(row1, col1-1, 1), penRight=sheet->getPen(row1, col2, 1), | 386 | penLeft=sheet->getPen(row1, col1-1, 1), penRight=sheet->getPen(row1, col2, 1), |
373 | penVert=sheet->getPen(row1, col1, 1), penHorz=sheet->getPen(row1, col1, 0), | 387 | penVert=sheet->getPen(row1, col1, 1), penHorz=sheet->getPen(row1, col1, 0), |
374 | penDefault=borderEditor->getDefaultPen(); | 388 | penDefault=borderEditor->getDefaultPen(); |
375 | for (row=row1+1; row<=row2; ++row) | 389 | for (row=row1+1; row<=row2; ++row) |
376 | if (sheet->getPen(row, col1-1, 1)!=penLeft) | 390 | if (sheet->getPen(row, col1-1, 1)!=penLeft) |
377 | { | 391 | { |
378 | penLeft=penDefault; | 392 | penLeft=penDefault; |
379 | break; | 393 | break; |
380 | } | 394 | } |
381 | for (row=row1+1; row<=row2; ++row) | 395 | for (row=row1+1; row<=row2; ++row) |
382 | if (sheet->getPen(row, col2, 1)!=penRight) | 396 | if (sheet->getPen(row, col2, 1)!=penRight) |
383 | { | 397 | { |
384 | penRight=penDefault; | 398 | penRight=penDefault; |
385 | break; | 399 | break; |
386 | } | 400 | } |
387 | for (col=col1+1; col<=col2; ++col) | 401 | for (col=col1+1; col<=col2; ++col) |
388 | if (sheet->getPen(row1-1, col, 0)!=penTop) | 402 | if (sheet->getPen(row1-1, col, 0)!=penTop) |
389 | { | 403 | { |
390 | penTop=penDefault; | 404 | penTop=penDefault; |
391 | break; | 405 | break; |
392 | } | 406 | } |
393 | for (col=col1+1; col<=col2; ++col) | 407 | for (col=col1+1; col<=col2; ++col) |
394 | if (sheet->getPen(row2, col, 0)!=penBottom) | 408 | if (sheet->getPen(row2, col, 0)!=penBottom) |
395 | { | 409 | { |
396 | penBottom=penDefault; | 410 | penBottom=penDefault; |
397 | break; | 411 | break; |
398 | } | 412 | } |
399 | for (row=row1; row<=row2; ++row) | 413 | for (row=row1; row<=row2; ++row) |
400 | for (col=col1; col<col2; ++col) | 414 | for (col=col1; col<col2; ++col) |
401 | if (sheet->getPen(row, col, 1)!=penVert) | 415 | if (sheet->getPen(row, col, 1)!=penVert) |
402 | { | 416 | { |
403 | penVert=penDefault; | 417 | penVert=penDefault; |
404 | break; | 418 | break; |
405 | } | 419 | } |
406 | for (row=row1; row<row2; ++row) | 420 | for (row=row1; row<row2; ++row) |
407 | for (col=col1; col<=col2; ++col) | 421 | for (col=col1; col<=col2; ++col) |
408 | if (sheet->getPen(row, col, 0)!=penHorz) | 422 | if (sheet->getPen(row, col, 0)!=penHorz) |
409 | { | 423 | { |
410 | penHorz=penDefault; | 424 | penHorz=penDefault; |
411 | break; | 425 | break; |
412 | } | 426 | } |
413 | 427 | ||
414 | borderEditor->setPen(penTop, BorderEditor::Top); | 428 | borderEditor->setPen(penTop, BorderEditor::Top); |
415 | borderEditor->setPen(penBottom, BorderEditor::Bottom); | 429 | borderEditor->setPen(penBottom, BorderEditor::Bottom); |
416 | borderEditor->setPen(penLeft, BorderEditor::Left); | 430 | borderEditor->setPen(penLeft, BorderEditor::Left); |
417 | borderEditor->setPen(penRight, BorderEditor::Right); | 431 | borderEditor->setPen(penRight, BorderEditor::Right); |
418 | borderEditor->setPen(penVert, BorderEditor::Vert); | 432 | borderEditor->setPen(penVert, BorderEditor::Vert); |
419 | borderEditor->setPen(penHorz, BorderEditor::Horz); | 433 | borderEditor->setPen(penHorz, BorderEditor::Horz); |
420 | 434 | ||
421 | setBrushBackground(sheet->getBrush(row1, col1)); | 435 | setBrushBackground(sheet->getBrush(row1, col1)); |
422 | setTextFont(sheet->getFont(row1, col1), sheet->getFontColor(row1, col1)); | 436 | setTextFont(sheet->getFont(row1, col1), sheet->getFontColor(row1, col1)); |
423 | setTextAlign(sheet->getAlignment(row1, col1)); | 437 | setTextAlign(sheet->getAlignment(row1, col1)); |
424 | 438 | ||
425 | if (QDialog::exec()==QDialog::Accepted) | 439 | if (QDialog::exec()==QDialog::Accepted) |
426 | { | 440 | { |
427 | penTop=borderEditor->getPen(BorderEditor::Top); | 441 | penTop=borderEditor->getPen(BorderEditor::Top); |
428 | penBottom=borderEditor->getPen(BorderEditor::Bottom); | 442 | penBottom=borderEditor->getPen(BorderEditor::Bottom); |
429 | penLeft=borderEditor->getPen(BorderEditor::Left); | 443 | penLeft=borderEditor->getPen(BorderEditor::Left); |
430 | penRight=borderEditor->getPen(BorderEditor::Right); | 444 | penRight=borderEditor->getPen(BorderEditor::Right); |
431 | penVert=borderEditor->getPen(BorderEditor::Vert); | 445 | penVert=borderEditor->getPen(BorderEditor::Vert); |
432 | penHorz=borderEditor->getPen(BorderEditor::Horz); | 446 | penHorz=borderEditor->getPen(BorderEditor::Horz); |
433 | 447 | ||
434 | if (penTop!=penDefault) | 448 | if (penTop!=penDefault) |
435 | for (col=col1; col<=col2; ++col) | 449 | for (col=col1; col<=col2; ++col) |
436 | sheet->setPen(row1-1, col, 0, penTop); | 450 | sheet->setPen(row1-1, col, 0, penTop); |
437 | if (penBottom!=penDefault) | 451 | if (penBottom!=penDefault) |
438 | for (col=col1; col<=col2; ++col) | 452 | for (col=col1; col<=col2; ++col) |
439 | sheet->setPen(row2, col, 0, penBottom); | 453 | sheet->setPen(row2, col, 0, penBottom); |
440 | if (penLeft!=penDefault) | 454 | if (penLeft!=penDefault) |
441 | for (row=row1; row<=row2; ++row) | 455 | for (row=row1; row<=row2; ++row) |
442 | sheet->setPen(row, col1-1, 1, penLeft); | 456 | sheet->setPen(row, col1-1, 1, penLeft); |
443 | if (penRight!=penDefault) | 457 | if (penRight!=penDefault) |
444 | for (row=row1; row<=row2; ++row) | 458 | for (row=row1; row<=row2; ++row) |
445 | sheet->setPen(row, col2, 1, penRight); | 459 | sheet->setPen(row, col2, 1, penRight); |
446 | if (penVert!=penDefault) | 460 | if (penVert!=penDefault) |
447 | for (row=row1; row<=row2; ++row) | 461 | for (row=row1; row<=row2; ++row) |
448 | for (col=col1; col<col2; ++col) | 462 | for (col=col1; col<col2; ++col) |
449 | sheet->setPen(row, col, 1, penVert); | 463 | sheet->setPen(row, col, 1, penVert); |
450 | if (penHorz!=penDefault) | 464 | if (penHorz!=penDefault) |
451 | for (row=row1; row<row2; ++row) | 465 | for (row=row1; row<row2; ++row) |
452 | for (col=col1; col<=col2; ++col) | 466 | for (col=col1; col<=col2; ++col) |
453 | sheet->setPen(row, col, 0, penHorz); | 467 | sheet->setPen(row, col, 0, penHorz); |
454 | 468 | ||
455 | if (changedBrush) | 469 | if (changedBrush) |
456 | { | 470 | { |
457 | for (row=row1; row<=row2; ++row) | 471 | for (row=row1; row<=row2; ++row) |
458 | for (col=col1; col<=col2; ++col) | 472 | for (col=col1; col<=col2; ++col) |
459 | sheet->setBrush(row, col, brushBackground); | 473 | sheet->setBrush(row, col, brushBackground); |
460 | } | 474 | } |
461 | 475 | ||
462 | if (changedAlign) | 476 | if (changedAlign) |
463 | { | 477 | { |
464 | for (row=row1; row<=row2; ++row) | 478 | for (row=row1; row<=row2; ++row) |
465 | for (col=col1; col<=col2; ++col) | 479 | for (col=col1; col<=col2; ++col) |
466 | sheet->setTextAlign(row, col, textAlignment); | 480 | sheet->setTextAlign(row, col, textAlignment); |
467 | } | 481 | } |
468 | 482 | ||
469 | if (changedFont) | 483 | if (changedFont) |
470 | { | 484 | { |
471 | for (row=row1; row<=row2; ++row) | 485 | for (row=row1; row<=row2; ++row) |
472 | for (col=col1; col<=col2; ++col) | 486 | for (col=col1; col<=col2; ++col) |
473 | sheet->setTextFont(row, col, fontFont, fontColor); | 487 | sheet->setTextFont(row, col, fontFont, fontColor); |
474 | } | 488 | } |
475 | return QDialog::Accepted; | 489 | return QDialog::Accepted; |
476 | } | 490 | } |
477 | return QDialog::Rejected; | 491 | return QDialog::Rejected; |
478 | } | 492 | } |
479 | 493 | ||
480 | // | 494 | // |
481 | // Border Editor | 495 | // Border Editor |
482 | // | 496 | // |
483 | 497 | ||
484 | BorderEditor::BorderEditor(QWidget *parent=0) | 498 | BorderEditor::BorderEditor(QWidget *parent=0) |
485 | :QFrame(parent) | 499 | :QFrame(parent) |
486 | { | 500 | { |
487 | setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); | 501 | setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); |
488 | } | 502 | } |
489 | 503 | ||
490 | BorderEditor::~BorderEditor() | 504 | BorderEditor::~BorderEditor() |
491 | { | 505 | { |
492 | } | 506 | } |
493 | 507 | ||
494 | void BorderEditor::drawContents(QPainter *p) | 508 | void BorderEditor::drawContents(QPainter *p) |
495 | { | 509 | { |
496 | QFrame::drawContents(p); | 510 | QFrame::drawContents(p); |
497 | 511 | ||
498 | int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3; | 512 | int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3; |
499 | int lineFirstX=x+width/6, lineFirstY=y+height/6, lineLastX=contentsRect().right()-width/6, lineLastY=contentsRect().bottom()-height/6; | 513 | int lineFirstX=x+width/6, lineFirstY=y+height/6, lineLastX=contentsRect().right()-width/6, lineLastY=contentsRect().bottom()-height/6; |
500 | 514 | ||
501 | p->fillRect(contentsRect(), Qt::white); | 515 | p->fillRect(contentsRect(), Qt::white); |
502 | 516 | ||
503 | p->fillRect(x+width/3, y+height/3, width, height, Qt::gray); | 517 | p->fillRect(x+width/3, y+height/3, width, height, Qt::gray); |
504 | p->fillRect(x+(5*width/3), y+height/3, width, height, Qt::gray); | 518 | p->fillRect(x+(5*width/3), y+height/3, width, height, Qt::gray); |
505 | p->fillRect(x+width/3, y+(5*height)/3, width, height, Qt::gray); | 519 | p->fillRect(x+width/3, y+(5*height)/3, width, height, Qt::gray); |
506 | p->fillRect(x+(5*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); |
507 | 521 | ||
508 | if (penTop.width()>0) | 522 | if (penTop.width()>0) |
509 | { | 523 | { |
510 | p->setPen(penTop); | 524 | p->setPen(penTop); |
511 | p->drawLine(lineFirstX, lineFirstY, lineLastX, lineFirstY); | 525 | p->drawLine(lineFirstX, lineFirstY, lineLastX, lineFirstY); |
512 | } | 526 | } |
513 | if (penBottom.width()>0) | 527 | if (penBottom.width()>0) |
514 | { | 528 | { |
515 | p->setPen(penBottom); | 529 | p->setPen(penBottom); |
516 | p->drawLine(lineFirstX, lineLastY, lineLastX, lineLastY); | 530 | p->drawLine(lineFirstX, lineLastY, lineLastX, lineLastY); |
517 | } | 531 | } |
518 | if (penHorz.width()>0) | 532 | if (penHorz.width()>0) |
519 | { | 533 | { |
520 | p->setPen(penHorz); | 534 | p->setPen(penHorz); |
521 | p->drawLine(lineFirstX, y+contentsRect().height()/2, lineLastX, y+contentsRect().height()/2); | 535 | p->drawLine(lineFirstX, y+contentsRect().height()/2, lineLastX, y+contentsRect().height()/2); |
522 | } | 536 | } |
523 | if (penLeft.width()>0) | 537 | if (penLeft.width()>0) |
524 | { | 538 | { |
525 | p->setPen(penLeft); | 539 | p->setPen(penLeft); |
526 | p->drawLine(lineFirstX, lineFirstY, lineFirstX, lineLastY); | 540 | p->drawLine(lineFirstX, lineFirstY, lineFirstX, lineLastY); |
527 | } | 541 | } |
528 | if (penRight.width()>0) | 542 | if (penRight.width()>0) |
529 | { | 543 | { |
530 | p->setPen(penRight); | 544 | p->setPen(penRight); |
531 | p->drawLine(lineLastX, lineFirstY, lineLastX, lineLastY); | 545 | p->drawLine(lineLastX, lineFirstY, lineLastX, lineLastY); |
532 | } | 546 | } |
533 | if (penVert.width()>0) | 547 | if (penVert.width()>0) |
534 | { | 548 | { |
535 | p->setPen(penVert); | 549 | p->setPen(penVert); |
536 | p->drawLine(x+contentsRect().width()/2, lineFirstY, x+contentsRect().width()/2, lineLastY); | 550 | p->drawLine(x+contentsRect().width()/2, lineFirstY, x+contentsRect().width()/2, lineLastY); |
537 | } | 551 | } |
538 | } | 552 | } |
539 | 553 | ||
540 | void BorderEditor::setPen(const QPen &pen, BorderArea area) | 554 | void BorderEditor::setPen(const QPen &pen, BorderArea area) |
541 | { | 555 | { |
542 | switch (area) | 556 | switch (area) |
543 | { | 557 | { |
544 | case Top: penTop=pen; break; | 558 | case Top: penTop=pen; break; |
545 | case Bottom: penBottom=pen; break; | 559 | case Bottom: penBottom=pen; break; |
546 | case Left: penLeft=pen; break; | 560 | case Left: penLeft=pen; break; |
547 | case Right: penRight=pen; break; | 561 | case Right: penRight=pen; break; |
548 | case Horz: penHorz=pen; break; | 562 | case Horz: penHorz=pen; break; |
549 | case Vert: penVert=pen; break; | 563 | case Vert: penVert=pen; break; |
550 | }; | 564 | }; |
551 | update(); | 565 | update(); |
552 | } | 566 | } |
553 | 567 | ||
554 | void BorderEditor::mouseReleaseEvent(QMouseEvent *e) | 568 | void BorderEditor::mouseReleaseEvent(QMouseEvent *e) |
555 | { | 569 | { |
556 | QFrame::mouseReleaseEvent(e); | 570 | QFrame::mouseReleaseEvent(e); |
557 | 571 | ||
558 | int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3; | 572 | int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3; |
559 | BorderArea area=None; | 573 | BorderArea area=None; |
560 | 574 | ||
561 | if (e->x()<x+width/3) area=Left; | 575 | if (e->x()<x+width/3) area=Left; |
562 | if (e->x()>x+(8*width)/3) area=Right; | 576 | if (e->x()>x+(8*width)/3) area=Right; |
563 | if (e->x()>x+(4*width)/3 && e->x()<x+(5*width)/3) area=Vert; | 577 | if (e->x()>x+(4*width)/3 && e->x()<x+(5*width)/3) area=Vert; |
564 | 578 | ||
565 | if (e->y()<y+height/3) area=Top; | 579 | if (e->y()<y+height/3) area=Top; |
566 | if (e->y()>y+(8*height)/3) area=Bottom; | 580 | if (e->y()>y+(8*height)/3) area=Bottom; |
567 | if (e->y()>y+(4*height)/3 && e->y()<y+(5*height)/3) area=Horz; | 581 | if (e->y()>y+(4*height)/3 && e->y()<y+(5*height)/3) area=Horz; |
568 | 582 | ||
569 | if (area!=None) | 583 | if (area!=None) |
570 | emit clicked(area); | 584 | emit clicked(area); |
571 | } | 585 | } |
572 | 586 | ||
573 | QPen BorderEditor::getPen(BorderArea area) | 587 | QPen BorderEditor::getPen(BorderArea area) |
574 | { | 588 | { |
575 | switch (area) | 589 | switch (area) |
576 | { | 590 | { |
577 | case Top: return penTop; | 591 | case Top: return penTop; |
578 | case Bottom: return penBottom; | 592 | case Bottom: return penBottom; |
579 | case Left: return penLeft; | 593 | case Left: return penLeft; |
580 | case Right: return penRight; | 594 | case Right: return penRight; |
581 | case Horz: return penHorz; | 595 | case Horz: return penHorz; |
582 | case Vert: return penVert; | 596 | case Vert: return penVert; |
583 | }; | 597 | }; |
584 | return getDefaultPen(); | 598 | return getDefaultPen(); |
585 | } | 599 | } |
diff --git a/noncore/apps/opie-sheet/cellformat.h b/noncore/apps/opie-sheet/cellformat.h index b552153..b569b7f 100644 --- a/noncore/apps/opie-sheet/cellformat.h +++ b/noncore/apps/opie-sheet/cellformat.h | |||
@@ -1,106 +1,120 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #ifndef CELLFORMAT_H | 15 | #ifndef CELLFORMAT_H |
2 | #define CELLFORMAT_H | 16 | #define CELLFORMAT_H |
3 | 17 | ||
4 | #include <qpe/fontdatabase.h> | 18 | #include <qpe/fontdatabase.h> |
5 | #include <qdialog.h> | 19 | #include <qdialog.h> |
6 | #include <qtabwidget.h> | 20 | #include <qtabwidget.h> |
7 | #include <qlayout.h> | 21 | #include <qlayout.h> |
8 | #include <qcombobox.h> | 22 | #include <qcombobox.h> |
9 | #include <qcheckbox.h> | 23 | #include <qcheckbox.h> |
10 | #include <qpushbutton.h> | 24 | #include <qpushbutton.h> |
11 | 25 | ||
12 | #include "sheet.h" | 26 | #include "sheet.h" |
13 | 27 | ||
14 | class BorderEditor: public QFrame | 28 | class BorderEditor: public QFrame |
15 | { | 29 | { |
16 | Q_OBJECT | 30 | Q_OBJECT |
17 | 31 | ||
18 | // QT objects | 32 | // QT objects |
19 | QPen penTop, penBottom, penLeft, penRight, penHorz, penVert; | 33 | QPen penTop, penBottom, penLeft, penRight, penHorz, penVert; |
20 | 34 | ||
21 | // Private functions | 35 | // Private functions |
22 | void drawContents(QPainter *p); | 36 | void drawContents(QPainter *p); |
23 | 37 | ||
24 | // Reimplemented QFrame functions | 38 | // Reimplemented QFrame functions |
25 | void mouseReleaseEvent(QMouseEvent *e); | 39 | void mouseReleaseEvent(QMouseEvent *e); |
26 | 40 | ||
27 | public: | 41 | public: |
28 | // Definitions | 42 | // Definitions |
29 | enum BorderArea {None, Top, Bottom, Left, Right, Horz, Vert}; | 43 | enum BorderArea {None, Top, Bottom, Left, Right, Horz, Vert}; |
30 | 44 | ||
31 | BorderEditor(QWidget *parent=0); | 45 | BorderEditor(QWidget *parent=0); |
32 | ~BorderEditor(); | 46 | ~BorderEditor(); |
33 | 47 | ||
34 | void setPen(const QPen &pen, BorderArea area); | 48 | void setPen(const QPen &pen, BorderArea area); |
35 | QPen getPen(BorderArea area); | 49 | QPen getPen(BorderArea area); |
36 | QPen getDefaultPen() { return QPen(Qt::black, 1, Qt::DotLine); } | 50 | QPen getDefaultPen() { return QPen(Qt::black, 1, Qt::DotLine); } |
37 | 51 | ||
38 | signals: | 52 | signals: |
39 | void clicked(BorderEditor::BorderArea); | 53 | void clicked(BorderEditor::BorderArea); |
40 | }; | 54 | }; |
41 | 55 | ||
42 | class CellFormat: public QDialog | 56 | class CellFormat: public QDialog |
43 | { | 57 | { |
44 | Q_OBJECT | 58 | Q_OBJECT |
45 | 59 | ||
46 | enum comboType {COMBO_OTHER, COMBO_WIDTH, COMBO_FONT, COMBO_SIZE, COMBO_STYLE, COMBO_COLOR, COMBO_VALIGN, COMBO_HALIGN}; | 60 | enum comboType {COMBO_OTHER, COMBO_WIDTH, COMBO_FONT, COMBO_SIZE, COMBO_STYLE, COMBO_COLOR, COMBO_VALIGN, COMBO_HALIGN}; |
47 | 61 | ||
48 | // QT objects | 62 | // QT objects |
49 | QBoxLayout *box; | 63 | QBoxLayout *box; |
50 | QTabWidget *tabs; | 64 | QTabWidget *tabs; |
51 | QWidget *widgetBorders, *widgetBackground, *widgetFont, *widgetAlignment; | 65 | QWidget *widgetBorders, *widgetBackground, *widgetFont, *widgetAlignment; |
52 | QComboBox *comboBordersWidth, *comboBordersColor, *comboBackgroundColor, *comboBackgroundStyle, *comboFontColor, *comboFontSize, *comboFontFamily, *comboAlignmentVertical, *comboAlignmentHorizontal; | 66 | QComboBox *comboBordersWidth, *comboBordersColor, *comboBackgroundColor, *comboBackgroundStyle, *comboFontColor, *comboFontSize, *comboFontFamily, *comboAlignmentVertical, *comboAlignmentHorizontal; |
53 | QCheckBox *checkFontBold, *checkFontItalic, *checkAlignmentWrap; | 67 | QCheckBox *checkFontBold, *checkFontItalic, *checkAlignmentWrap; |
54 | QPushButton *buttonBordersDefaults, *buttonBackgroundDefaults, *buttonFontDefaults, *buttonAlignmentDefaults; | 68 | QPushButton *buttonBordersDefaults, *buttonBackgroundDefaults, *buttonFontDefaults, *buttonAlignmentDefaults; |
55 | QFrame *frameBackground, *frameFont, *frameAlignment; | 69 | QFrame *frameBackground, *frameFont, *frameAlignment; |
56 | QBrush brushBackground; | 70 | QBrush brushBackground; |
57 | QFont fontFont; | 71 | QFont fontFont; |
58 | QColor fontColor; | 72 | QColor fontColor; |
59 | Qt::AlignmentFlags textAlignment; | 73 | Qt::AlignmentFlags textAlignment; |
60 | FontDatabase fontDB; | 74 | FontDatabase fontDB; |
61 | 75 | ||
62 | // Other objects & variables | 76 | // Other objects & variables |
63 | Sheet *sheet; | 77 | Sheet *sheet; |
64 | BorderEditor *borderEditor; | 78 | BorderEditor *borderEditor; |
65 | bool changedFont, changedAlign, changedBrush; | 79 | bool changedFont, changedAlign, changedBrush; |
66 | 80 | ||
67 | // Private functions | 81 | // Private functions |
68 | void createWidthCombo(QComboBox *combo); | 82 | void createWidthCombo(QComboBox *combo); |
69 | void createFontCombo(QComboBox *combo); | 83 | void createFontCombo(QComboBox *combo); |
70 | void createHAlignCombo(QComboBox *combo); | 84 | void createHAlignCombo(QComboBox *combo); |
71 | void createVAlignCombo(QComboBox *combo); | 85 | void createVAlignCombo(QComboBox *combo); |
72 | void createStyleCombo(QComboBox *combo); | 86 | void createStyleCombo(QComboBox *combo); |
73 | void createSizeCombo(QComboBox *combo); | 87 | void createSizeCombo(QComboBox *combo); |
74 | void createColorCombo(QComboBox *combo); | 88 | void createColorCombo(QComboBox *combo); |
75 | QComboBox *createCombo(comboType type, QWidget *parent, const QString &caption, int y); | 89 | QComboBox *createCombo(comboType type, QWidget *parent, const QString &caption, int y); |
76 | 90 | ||
77 | int findHAlignIndex(Qt::AlignmentFlags flag); | 91 | int findHAlignIndex(Qt::AlignmentFlags flag); |
78 | int findVAlignIndex(Qt::AlignmentFlags flag); | 92 | int findVAlignIndex(Qt::AlignmentFlags flag); |
79 | int findComboItemIndex(QComboBox *combo, const QString &item); | 93 | int findComboItemIndex(QComboBox *combo, const QString &item); |
80 | int findColorIndex(const QColor &color); | 94 | int findColorIndex(const QColor &color); |
81 | int findBrushStyleIndex(Qt::BrushStyle style); | 95 | int findBrushStyleIndex(Qt::BrushStyle style); |
82 | 96 | ||
83 | private slots: | 97 | private slots: |
84 | void borderClicked(BorderEditor::BorderArea area); | 98 | void borderClicked(BorderEditor::BorderArea area); |
85 | void backgroundClicked(int index); | 99 | void backgroundClicked(int index); |
86 | void fontClicked(bool on); | 100 | void fontClicked(bool on); |
87 | void fontClicked(int index); | 101 | void fontClicked(int index); |
88 | void alignClicked(bool on); | 102 | void alignClicked(bool on); |
89 | void alignClicked(int index); | 103 | void alignClicked(int index); |
90 | void slotBordersDefaults(); | 104 | void slotBordersDefaults(); |
91 | void slotBackgroundDefaults(); | 105 | void slotBackgroundDefaults(); |
92 | void slotFontDefaults(); | 106 | void slotFontDefaults(); |
93 | void slotAlignmentDefaults(); | 107 | void slotAlignmentDefaults(); |
94 | 108 | ||
95 | public: | 109 | public: |
96 | CellFormat(QWidget *parent=0); | 110 | CellFormat(QWidget *parent=0); |
97 | ~CellFormat(); | 111 | ~CellFormat(); |
98 | 112 | ||
99 | int exec(Sheet *s); | 113 | int exec(Sheet *s); |
100 | 114 | ||
101 | void setTextAlign(Qt::AlignmentFlags flags); | 115 | void setTextAlign(Qt::AlignmentFlags flags); |
102 | void setTextFont(const QFont &font, const QColor &color); | 116 | void setTextFont(const QFont &font, const QColor &color); |
103 | void setBrushBackground(const QBrush &brush); | 117 | void setBrushBackground(const QBrush &brush); |
104 | }; | 118 | }; |
105 | 119 | ||
106 | #endif | 120 | #endif |
diff --git a/noncore/apps/opie-sheet/finddlg.cpp b/noncore/apps/opie-sheet/finddlg.cpp index cfe2f82..d1237ca 100644 --- a/noncore/apps/opie-sheet/finddlg.cpp +++ b/noncore/apps/opie-sheet/finddlg.cpp | |||
@@ -1,70 +1,84 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #include <qlabel.h> | 15 | #include <qlabel.h> |
2 | #include <qradiobutton.h> | 16 | #include <qradiobutton.h> |
3 | #include "finddlg.h" | 17 | #include "finddlg.h" |
4 | 18 | ||
5 | FindDialog::FindDialog(QWidget *parent=0) | 19 | FindDialog::FindDialog(QWidget *parent=0) |
6 | :QDialog(parent, 0, TRUE) | 20 | :QDialog(parent, 0, TRUE) |
7 | { | 21 | { |
8 | // Main widget | 22 | // Main widget |
9 | tabs=new QTabWidget(this); | 23 | tabs=new QTabWidget(this); |
10 | widgetFind=new QWidget(tabs); | 24 | widgetFind=new QWidget(tabs); |
11 | widgetOptions=new QWidget(tabs); | 25 | widgetOptions=new QWidget(tabs); |
12 | tabs->addTab(widgetFind, tr("&Find && Replace")); | 26 | tabs->addTab(widgetFind, tr("&Find && Replace")); |
13 | tabs->addTab(widgetOptions, tr("&Options")); | 27 | tabs->addTab(widgetOptions, tr("&Options")); |
14 | 28 | ||
15 | // Find tab | 29 | // Find tab |
16 | QLabel *label=new QLabel(tr("&Search for:"), widgetFind); | 30 | QLabel *label=new QLabel(tr("&Search for:"), widgetFind); |
17 | label->setGeometry(10, 10, 215, 20); | 31 | label->setGeometry(10, 10, 215, 20); |
18 | editFind=new QLineEdit(widgetFind); | 32 | editFind=new QLineEdit(widgetFind); |
19 | editFind->setGeometry(10, 40, 215, 20); | 33 | editFind->setGeometry(10, 40, 215, 20); |
20 | label->setBuddy(editFind); | 34 | label->setBuddy(editFind); |
21 | 35 | ||
22 | label=new QLabel(tr("&Replace with:"), widgetFind); | 36 | label=new QLabel(tr("&Replace with:"), widgetFind); |
23 | label->setGeometry(10, 80, 215, 20); | 37 | label->setGeometry(10, 80, 215, 20); |
24 | editReplace=new QLineEdit(widgetFind); | 38 | editReplace=new QLineEdit(widgetFind); |
25 | editReplace->setGeometry(10, 110, 215, 20); | 39 | editReplace->setGeometry(10, 110, 215, 20); |
26 | editReplace->setEnabled(FALSE); | 40 | editReplace->setEnabled(FALSE); |
27 | label->setBuddy(editReplace); | 41 | label->setBuddy(editReplace); |
28 | 42 | ||
29 | groupType=new QVButtonGroup(tr("&Type"), widgetFind); | 43 | groupType=new QVButtonGroup(tr("&Type"), widgetFind); |
30 | groupType->setGeometry(10, 150, 215, 90); | 44 | groupType->setGeometry(10, 150, 215, 90); |
31 | QRadioButton *radio=new QRadioButton(tr("&Find"), groupType); | 45 | QRadioButton *radio=new QRadioButton(tr("&Find"), groupType); |
32 | radio=new QRadioButton(tr("&Replace"), groupType); | 46 | radio=new QRadioButton(tr("&Replace"), groupType); |
33 | radio=new QRadioButton(tr("Replace &all"), groupType); | 47 | radio=new QRadioButton(tr("Replace &all"), groupType); |
34 | groupType->setButton(0); | 48 | groupType->setButton(0); |
35 | connect(groupType, SIGNAL(clicked(int)), this, SLOT(typeChanged(int))); | 49 | connect(groupType, SIGNAL(clicked(int)), this, SLOT(typeChanged(int))); |
36 | 50 | ||
37 | // Options tab | 51 | // Options tab |
38 | checkCase=new QCheckBox(tr("Match &case"), widgetOptions); | 52 | checkCase=new QCheckBox(tr("Match &case"), widgetOptions); |
39 | checkCase->setGeometry(10, 10, 215, 20); | 53 | checkCase->setGeometry(10, 10, 215, 20); |
40 | checkSelection=new QCheckBox(tr("Current &selection only"), widgetOptions); | 54 | checkSelection=new QCheckBox(tr("Current &selection only"), widgetOptions); |
41 | checkSelection->setGeometry(10, 40, 215, 20); | 55 | checkSelection->setGeometry(10, 40, 215, 20); |
42 | checkEntire=new QCheckBox(tr("&Entire cell"), widgetOptions); | 56 | checkEntire=new QCheckBox(tr("&Entire cell"), widgetOptions); |
43 | checkEntire->setGeometry(10, 70, 215, 20); | 57 | checkEntire->setGeometry(10, 70, 215, 20); |
44 | 58 | ||
45 | // Main widget | 59 | // Main widget |
46 | box=new QVBoxLayout(this); | 60 | box=new QVBoxLayout(this); |
47 | box->addWidget(tabs); | 61 | box->addWidget(tabs); |
48 | 62 | ||
49 | setCaption(tr("Find & Replace")); | 63 | setCaption(tr("Find & Replace")); |
50 | } | 64 | } |
51 | 65 | ||
52 | FindDialog::~FindDialog() | 66 | FindDialog::~FindDialog() |
53 | { | 67 | { |
54 | } | 68 | } |
55 | 69 | ||
56 | void FindDialog::typeChanged(int id) | 70 | void FindDialog::typeChanged(int id) |
57 | { | 71 | { |
58 | editReplace->setEnabled(id>0); | 72 | editReplace->setEnabled(id>0); |
59 | } | 73 | } |
60 | 74 | ||
61 | int FindDialog::exec(Sheet *s) | 75 | int FindDialog::exec(Sheet *s) |
62 | { | 76 | { |
63 | if (QDialog::exec()==QDialog::Accepted) | 77 | if (QDialog::exec()==QDialog::Accepted) |
64 | { | 78 | { |
65 | int id=groupType->id(groupType->selected()); | 79 | int id=groupType->id(groupType->selected()); |
66 | 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); |
67 | return QDialog::Accepted; | 81 | return QDialog::Accepted; |
68 | } | 82 | } |
69 | return QDialog::Rejected; | 83 | return QDialog::Rejected; |
70 | } | 84 | } |
diff --git a/noncore/apps/opie-sheet/finddlg.h b/noncore/apps/opie-sheet/finddlg.h index 02c9cdd..1af2da5 100644 --- a/noncore/apps/opie-sheet/finddlg.h +++ b/noncore/apps/opie-sheet/finddlg.h | |||
@@ -1,35 +1,49 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #ifndef FINDDLG_H | 15 | #ifndef FINDDLG_H |
2 | #define FINDDLG_H | 16 | #define FINDDLG_H |
3 | 17 | ||
4 | #include <qdialog.h> | 18 | #include <qdialog.h> |
5 | #include <qtabwidget.h> | 19 | #include <qtabwidget.h> |
6 | #include <qlayout.h> | 20 | #include <qlayout.h> |
7 | #include <qlineedit.h> | 21 | #include <qlineedit.h> |
8 | #include <qcheckbox.h> | 22 | #include <qcheckbox.h> |
9 | #include <qpushbutton.h> | 23 | #include <qpushbutton.h> |
10 | #include <qvbuttongroup.h> | 24 | #include <qvbuttongroup.h> |
11 | #include "sheet.h" | 25 | #include "sheet.h" |
12 | 26 | ||
13 | class FindDialog: public QDialog | 27 | class FindDialog: public QDialog |
14 | { | 28 | { |
15 | Q_OBJECT | 29 | Q_OBJECT |
16 | 30 | ||
17 | // QT objects | 31 | // QT objects |
18 | QBoxLayout *box; | 32 | QBoxLayout *box; |
19 | QTabWidget *tabs; | 33 | QTabWidget *tabs; |
20 | QWidget *widgetFind, *widgetOptions; | 34 | QWidget *widgetFind, *widgetOptions; |
21 | QCheckBox *checkCase, *checkSelection, *checkEntire; | 35 | QCheckBox *checkCase, *checkSelection, *checkEntire; |
22 | QLineEdit *editFind, *editReplace; | 36 | QLineEdit *editFind, *editReplace; |
23 | QVButtonGroup *groupType; | 37 | QVButtonGroup *groupType; |
24 | 38 | ||
25 | private slots: | 39 | private slots: |
26 | void typeChanged(int id); | 40 | void typeChanged(int id); |
27 | 41 | ||
28 | public: | 42 | public: |
29 | FindDialog(QWidget *parent=0); | 43 | FindDialog(QWidget *parent=0); |
30 | ~FindDialog(); | 44 | ~FindDialog(); |
31 | 45 | ||
32 | int exec(Sheet *s); | 46 | int exec(Sheet *s); |
33 | }; | 47 | }; |
34 | 48 | ||
35 | #endif | 49 | #endif |
diff --git a/noncore/apps/opie-sheet/main.cpp b/noncore/apps/opie-sheet/main.cpp index 236a579..e42b4a5 100644 --- a/noncore/apps/opie-sheet/main.cpp +++ b/noncore/apps/opie-sheet/main.cpp | |||
@@ -1,14 +1,28 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #include <qpe/qpeapplication.h> | 15 | #include <qpe/qpeapplication.h> |
2 | 16 | ||
3 | #include "mainwindow.h" | 17 | #include "mainwindow.h" |
4 | 18 | ||
5 | int main(int argc, char **argv) | 19 | int main(int argc, char **argv) |
6 | { | 20 | { |
7 | QPEApplication application(argc, argv); | 21 | QPEApplication application(argc, argv); |
8 | 22 | ||
9 | MainWindow windowMain; | 23 | MainWindow windowMain; |
10 | windowMain.setHelpFile(application.qpeDir()+"/help/html/"+QString(argv[0])+".html"); | 24 | windowMain.setHelpFile(application.qpeDir()+"/help/html/"+QString(argv[0])+".html"); |
11 | application.showMainDocumentWidget(&windowMain); | 25 | application.showMainDocumentWidget(&windowMain); |
12 | 26 | ||
13 | return application.exec(); | 27 | return application.exec(); |
14 | } | 28 | } |
diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp index a7441b1..9d69b8a 100644 --- a/noncore/apps/opie-sheet/mainwindow.cpp +++ b/noncore/apps/opie-sheet/mainwindow.cpp | |||
@@ -1,836 +1,850 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #include "mainwindow.h" | 15 | #include "mainwindow.h" |
2 | 16 | ||
3 | #include <qpe/filemanager.h> | 17 | #include <qpe/filemanager.h> |
4 | #include <qpe/qcopenvelope_qws.h> | 18 | #include <qpe/qcopenvelope_qws.h> |
5 | #include <qmessagebox.h> | 19 | #include <qmessagebox.h> |
6 | #include <qfile.h> | 20 | #include <qfile.h> |
7 | #include <qradiobutton.h> | 21 | #include <qradiobutton.h> |
8 | #include "cellformat.h" | 22 | #include "cellformat.h" |
9 | #include "numberdlg.h" | 23 | #include "numberdlg.h" |
10 | #include "textdlg.h" | 24 | #include "textdlg.h" |
11 | #include "sortdlg.h" | 25 | #include "sortdlg.h" |
12 | #include "finddlg.h" | 26 | #include "finddlg.h" |
13 | 27 | ||
14 | #include "file-new.xpm" | 28 | #include "file-new.xpm" |
15 | #include "file-open.xpm" | 29 | #include "file-open.xpm" |
16 | #include "file-save.xpm" | 30 | #include "file-save.xpm" |
17 | #include "edit-cancel.xpm" | 31 | #include "edit-cancel.xpm" |
18 | #include "edit-accept.xpm" | 32 | #include "edit-accept.xpm" |
19 | #include "help-general.xpm" | 33 | #include "help-general.xpm" |
20 | #include "func-plus.xpm" | 34 | #include "func-plus.xpm" |
21 | #include "func-minus.xpm" | 35 | #include "func-minus.xpm" |
22 | #include "func-cross.xpm" | 36 | #include "func-cross.xpm" |
23 | #include "func-divide.xpm" | 37 | #include "func-divide.xpm" |
24 | #include "func-paran-open.xpm" | 38 | #include "func-paran-open.xpm" |
25 | #include "func-paran-close.xpm" | 39 | #include "func-paran-close.xpm" |
26 | #include "func-comma.xpm" | 40 | #include "func-comma.xpm" |
27 | #include "func-func.xpm" | 41 | #include "func-func.xpm" |
28 | #include "func-equal.xpm" | 42 | #include "func-equal.xpm" |
29 | #include "cell-select.xpm" | 43 | #include "cell-select.xpm" |
30 | 44 | ||
31 | #define DEFAULT_NUM_ROWS 199 | 45 | #define DEFAULT_NUM_ROWS 199 |
32 | #define DEFAULT_NUM_COLS (26*3) | 46 | #define DEFAULT_NUM_COLS (26*3) |
33 | #define DEFAULT_NUM_SHEETS 3 | 47 | #define DEFAULT_NUM_SHEETS 3 |
34 | 48 | ||
35 | MainWindow::MainWindow() | 49 | MainWindow::MainWindow() |
36 | :QMainWindow() | 50 | :QMainWindow() |
37 | { | 51 | { |
38 | // initialize variables | 52 | // initialize variables |
39 | documentModified=FALSE; | 53 | documentModified=FALSE; |
40 | 54 | ||
41 | // construct objects | 55 | // construct objects |
42 | fileSelector=new FileSelector("application/sheet-qt", this, QString::null); | 56 | fileSelector=new FileSelector("application/sheet-qt", this, QString::null); |
43 | connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide())); | 57 | connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide())); |
44 | connect(fileSelector, SIGNAL(newSelected(const DocLnk &)), this, SLOT(selectorFileNew(const DocLnk &))); | 58 | connect(fileSelector, SIGNAL(newSelected(const DocLnk &)), this, SLOT(selectorFileNew(const DocLnk &))); |
45 | connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(selectorFileOpen(const DocLnk &))); | 59 | connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(selectorFileOpen(const DocLnk &))); |
46 | 60 | ||
47 | listSheets.setAutoDelete(TRUE); | 61 | listSheets.setAutoDelete(TRUE); |
48 | 62 | ||
49 | initActions(); | 63 | initActions(); |
50 | initMenu(); | 64 | initMenu(); |
51 | initEditToolbar(); | 65 | initEditToolbar(); |
52 | initFunctionsToolbar(); | 66 | initFunctionsToolbar(); |
53 | initStandardToolbar(); | 67 | initStandardToolbar(); |
54 | initSheet(); | 68 | initSheet(); |
55 | 69 | ||
56 | // set window title | 70 | // set window title |
57 | setCaption(tr("Opie Sheet")); | 71 | setCaption(tr("Opie Sheet")); |
58 | 72 | ||
59 | // create sheets | 73 | // create sheets |
60 | selectorFileNew(currentDoc); | 74 | selectorFileNew(currentDoc); |
61 | } | 75 | } |
62 | 76 | ||
63 | MainWindow::~MainWindow() | 77 | MainWindow::~MainWindow() |
64 | { | 78 | { |
65 | } | 79 | } |
66 | 80 | ||
67 | void MainWindow::documentSave(DocLnk &lnkDoc) | 81 | void MainWindow::documentSave(DocLnk &lnkDoc) |
68 | { | 82 | { |
69 | FileManager fm; | 83 | FileManager fm; |
70 | QByteArray streamBuffer; | 84 | QByteArray streamBuffer; |
71 | QDataStream stream(streamBuffer, IO_WriteOnly); | 85 | QDataStream stream(streamBuffer, IO_WriteOnly); |
72 | 86 | ||
73 | typeSheet *currentSheet=findSheet(sheet->getName()); | 87 | typeSheet *currentSheet=findSheet(sheet->getName()); |
74 | if (!currentSheet) | 88 | if (!currentSheet) |
75 | { | 89 | { |
76 | QMessageBox::critical(this, tr("Error"), tr("Inconsistency error!")); | 90 | QMessageBox::critical(this, tr("Error"), tr("Inconsistency error!")); |
77 | return; | 91 | return; |
78 | } | 92 | } |
79 | sheet->copySheetData(¤tSheet->data); | 93 | sheet->copySheetData(¤tSheet->data); |
80 | stream.writeRawBytes("SQT100", 6); | 94 | stream.writeRawBytes("SQT100", 6); |
81 | stream << (Q_UINT32)listSheets.count(); | 95 | stream << (Q_UINT32)listSheets.count(); |
82 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) | 96 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) |
83 | { | 97 | { |
84 | stream << tempSheet->name << (Q_UINT32)tempSheet->data.count(); | 98 | stream << tempSheet->name << (Q_UINT32)tempSheet->data.count(); |
85 | for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next()) | 99 | for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next()) |
86 | 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; | 100 | 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; |
87 | } | 101 | } |
88 | 102 | ||
89 | lnkDoc.setType("application/sheet-qt"); | 103 | lnkDoc.setType("application/sheet-qt"); |
90 | if (!fm.saveFile(lnkDoc, streamBuffer)) | 104 | if (!fm.saveFile(lnkDoc, streamBuffer)) |
91 | { | 105 | { |
92 | QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!")); | 106 | QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!")); |
93 | return; | 107 | return; |
94 | } | 108 | } |
95 | documentModified=FALSE; | 109 | documentModified=FALSE; |
96 | } | 110 | } |
97 | 111 | ||
98 | void MainWindow::documentOpen(const DocLnk &lnkDoc) | 112 | void MainWindow::documentOpen(const DocLnk &lnkDoc) |
99 | { | 113 | { |
100 | FileManager fm; | 114 | FileManager fm; |
101 | QByteArray streamBuffer; | 115 | QByteArray streamBuffer; |
102 | if (!lnkDoc.isValid() || !fm.loadFile(lnkDoc, streamBuffer)) | 116 | if (!lnkDoc.isValid() || !fm.loadFile(lnkDoc, streamBuffer)) |
103 | { | 117 | { |
104 | QMessageBox::critical(this, tr("Error"), tr("File cannot be opened!")); | 118 | QMessageBox::critical(this, tr("Error"), tr("File cannot be opened!")); |
105 | documentModified=FALSE; | 119 | documentModified=FALSE; |
106 | selectorFileNew(DocLnk()); | 120 | selectorFileNew(DocLnk()); |
107 | return; | 121 | return; |
108 | } | 122 | } |
109 | QDataStream stream(streamBuffer, IO_ReadOnly); | 123 | QDataStream stream(streamBuffer, IO_ReadOnly); |
110 | 124 | ||
111 | Q_UINT32 countSheet, countCell, i, j, row, col, alignment; | 125 | Q_UINT32 countSheet, countCell, i, j, row, col, alignment; |
112 | typeSheet *newSheet; | 126 | typeSheet *newSheet; |
113 | typeCellData *newCell; | 127 | typeCellData *newCell; |
114 | 128 | ||
115 | char fileFormat[7]; | 129 | char fileFormat[7]; |
116 | stream.readRawBytes(fileFormat, 6); | 130 | stream.readRawBytes(fileFormat, 6); |
117 | fileFormat[6]=0; | 131 | fileFormat[6]=0; |
118 | if ((QString)fileFormat!="SQT100") | 132 | if ((QString)fileFormat!="SQT100") |
119 | { | 133 | { |
120 | QMessageBox::critical(this, tr("Error"), tr("Invalid file format!")); | 134 | QMessageBox::critical(this, tr("Error"), tr("Invalid file format!")); |
121 | documentModified=FALSE; | 135 | documentModified=FALSE; |
122 | selectorFileNew(DocLnk()); | 136 | selectorFileNew(DocLnk()); |
123 | return; | 137 | return; |
124 | } | 138 | } |
125 | 139 | ||
126 | stream >> countSheet; | 140 | stream >> countSheet; |
127 | for (i=0; i<countSheet; ++i) | 141 | for (i=0; i<countSheet; ++i) |
128 | { | 142 | { |
129 | newSheet=new typeSheet; | 143 | newSheet=new typeSheet; |
130 | newSheet->data.setAutoDelete(TRUE); | 144 | newSheet->data.setAutoDelete(TRUE); |
131 | stream >> newSheet->name >> countCell; | 145 | stream >> newSheet->name >> countCell; |
132 | comboSheets->insertItem(newSheet->name); | 146 | comboSheets->insertItem(newSheet->name); |
133 | 147 | ||
134 | for (j=0; j<countCell; ++j) | 148 | for (j=0; j<countCell; ++j) |
135 | { | 149 | { |
136 | newCell=new typeCellData; | 150 | newCell=new typeCellData; |
137 | stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data; | 151 | stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data; |
138 | newCell->col=col; | 152 | newCell->col=col; |
139 | newCell->row=row; | 153 | newCell->row=row; |
140 | newCell->alignment=(Qt::AlignmentFlags)alignment; | 154 | newCell->alignment=(Qt::AlignmentFlags)alignment; |
141 | newSheet->data.append(newCell); | 155 | newSheet->data.append(newCell); |
142 | } | 156 | } |
143 | listSheets.append(newSheet); | 157 | listSheets.append(newSheet); |
144 | 158 | ||
145 | if (i==0) | 159 | if (i==0) |
146 | { | 160 | { |
147 | sheet->setName(newSheet->name); | 161 | sheet->setName(newSheet->name); |
148 | sheet->setSheetData(&newSheet->data); | 162 | sheet->setSheetData(&newSheet->data); |
149 | } | 163 | } |
150 | } | 164 | } |
151 | } | 165 | } |
152 | 166 | ||
153 | int MainWindow::saveCurrentFile(bool ask=TRUE) | 167 | int MainWindow::saveCurrentFile(bool ask=TRUE) |
154 | { | 168 | { |
155 | if (ask) | 169 | if (ask) |
156 | { | 170 | { |
157 | int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); | 171 | int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); |
158 | if (result!=QMessageBox::Yes) return result; | 172 | if (result!=QMessageBox::Yes) return result; |
159 | } | 173 | } |
160 | 174 | ||
161 | if (currentDoc.name().isEmpty() || !currentDoc.isValid()) | 175 | if (currentDoc.name().isEmpty() || !currentDoc.isValid()) |
162 | { | 176 | { |
163 | TextDialog dialogText(this); | 177 | TextDialog dialogText(this); |
164 | if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel; | 178 | if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel; |
165 | 179 | ||
166 | currentDoc.setName(dialogText.getValue()); | 180 | currentDoc.setName(dialogText.getValue()); |
167 | } | 181 | } |
168 | 182 | ||
169 | documentSave(currentDoc); | 183 | documentSave(currentDoc); |
170 | return QMessageBox::Yes; | 184 | return QMessageBox::Yes; |
171 | } | 185 | } |
172 | 186 | ||
173 | void MainWindow::copyDocLnk(const DocLnk &source, DocLnk &target) | 187 | void MainWindow::copyDocLnk(const DocLnk &source, DocLnk &target) |
174 | { | 188 | { |
175 | target.setName(source.name()); | 189 | target.setName(source.name()); |
176 | target.setFile(source.file()); | 190 | target.setFile(source.file()); |
177 | target.setLinkFile(source.linkFile()); | 191 | target.setLinkFile(source.linkFile()); |
178 | target.setComment(source.comment()); | 192 | target.setComment(source.comment()); |
179 | target.setType(source.type()); | 193 | target.setType(source.type()); |
180 | target.setCategories(source.categories()); | 194 | target.setCategories(source.categories()); |
181 | } | 195 | } |
182 | 196 | ||
183 | void MainWindow::selectorFileNew(const DocLnk &lnkDoc) | 197 | void MainWindow::selectorFileNew(const DocLnk &lnkDoc) |
184 | { | 198 | { |
185 | selectorHide(); | 199 | selectorHide(); |
186 | 200 | ||
187 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; | 201 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; |
188 | copyDocLnk(lnkDoc, currentDoc); | 202 | copyDocLnk(lnkDoc, currentDoc); |
189 | listSheets.clear(); | 203 | listSheets.clear(); |
190 | comboSheets->clear(); | 204 | comboSheets->clear(); |
191 | 205 | ||
192 | typeSheet *newSheet=createNewSheet(); | 206 | typeSheet *newSheet=createNewSheet(); |
193 | newSheet->data.setAutoDelete(TRUE); | 207 | newSheet->data.setAutoDelete(TRUE); |
194 | sheet->setName(newSheet->name); | 208 | sheet->setName(newSheet->name); |
195 | sheet->setSheetData(&newSheet->data); | 209 | sheet->setSheetData(&newSheet->data); |
196 | for (int i=1; i<DEFAULT_NUM_SHEETS; ++i) | 210 | for (int i=1; i<DEFAULT_NUM_SHEETS; ++i) |
197 | createNewSheet(); | 211 | createNewSheet(); |
198 | documentModified=FALSE; | 212 | documentModified=FALSE; |
199 | } | 213 | } |
200 | 214 | ||
201 | void MainWindow::closeEvent(QCloseEvent *e) | 215 | void MainWindow::closeEvent(QCloseEvent *e) |
202 | { | 216 | { |
203 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore(); | 217 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore(); |
204 | else e->accept(); | 218 | else e->accept(); |
205 | } | 219 | } |
206 | 220 | ||
207 | void MainWindow::selectorFileOpen(const DocLnk &lnkDoc) | 221 | void MainWindow::selectorFileOpen(const DocLnk &lnkDoc) |
208 | { | 222 | { |
209 | selectorHide(); | 223 | selectorHide(); |
210 | 224 | ||
211 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; | 225 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; |
212 | copyDocLnk(lnkDoc, currentDoc); | 226 | copyDocLnk(lnkDoc, currentDoc); |
213 | listSheets.clear(); | 227 | listSheets.clear(); |
214 | comboSheets->clear(); | 228 | comboSheets->clear(); |
215 | 229 | ||
216 | documentOpen(lnkDoc); | 230 | documentOpen(lnkDoc); |
217 | documentModified=FALSE; | 231 | documentModified=FALSE; |
218 | } | 232 | } |
219 | 233 | ||
220 | void MainWindow::selectorShow() | 234 | void MainWindow::selectorShow() |
221 | { | 235 | { |
222 | sheet->hide(); | 236 | sheet->hide(); |
223 | setCentralWidget(fileSelector); | 237 | setCentralWidget(fileSelector); |
224 | fileSelector->show(); | 238 | fileSelector->show(); |
225 | fileSelector->reread(); | 239 | fileSelector->reread(); |
226 | } | 240 | } |
227 | 241 | ||
228 | void MainWindow::selectorHide() | 242 | void MainWindow::selectorHide() |
229 | { | 243 | { |
230 | fileSelector->hide(); | 244 | fileSelector->hide(); |
231 | setCentralWidget(sheet); | 245 | setCentralWidget(sheet); |
232 | sheet->show(); | 246 | sheet->show(); |
233 | } | 247 | } |
234 | 248 | ||
235 | void MainWindow::slotFileNew() | 249 | void MainWindow::slotFileNew() |
236 | { | 250 | { |
237 | selectorFileNew(DocLnk()); | 251 | selectorFileNew(DocLnk()); |
238 | } | 252 | } |
239 | 253 | ||
240 | void MainWindow::slotFileOpen() | 254 | void MainWindow::slotFileOpen() |
241 | { | 255 | { |
242 | selectorShow(); | 256 | selectorShow(); |
243 | } | 257 | } |
244 | 258 | ||
245 | void MainWindow::slotFileSave() | 259 | void MainWindow::slotFileSave() |
246 | { | 260 | { |
247 | saveCurrentFile(FALSE); | 261 | saveCurrentFile(FALSE); |
248 | } | 262 | } |
249 | 263 | ||
250 | void MainWindow::setDocument(const QString &applnk_filename) | 264 | void MainWindow::setDocument(const QString &applnk_filename) |
251 | { | 265 | { |
252 | selectorFileOpen(DocLnk(applnk_filename)); | 266 | selectorFileOpen(DocLnk(applnk_filename)); |
253 | } | 267 | } |
254 | 268 | ||
255 | void MainWindow::initActions() | 269 | void MainWindow::initActions() |
256 | { | 270 | { |
257 | fileNew=new QAction(tr("New File"), QPixmap(file_new_xpm), tr("&New"), 0, this); | 271 | fileNew=new QAction(tr("New File"), QPixmap(file_new_xpm), tr("&New"), 0, this); |
258 | connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew())); | 272 | connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew())); |
259 | fileOpen=new QAction(tr("Open File"), QPixmap(file_open_xpm), tr("&Open"), 0, this); | 273 | fileOpen=new QAction(tr("Open File"), QPixmap(file_open_xpm), tr("&Open"), 0, this); |
260 | connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen())); | 274 | connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen())); |
261 | fileSave=new QAction(tr("Save File"), QPixmap(file_save_xpm), tr("&Save"), 0, this); | 275 | fileSave=new QAction(tr("Save File"), QPixmap(file_save_xpm), tr("&Save"), 0, this); |
262 | connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave())); | 276 | connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave())); |
263 | fileSaveAs=new QAction(tr("Save File As"), QPixmap(file_save_xpm), tr("Save &As"), 0, this); | 277 | fileSaveAs=new QAction(tr("Save File As"), QPixmap(file_save_xpm), tr("Save &As"), 0, this); |
264 | connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs())); | 278 | connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs())); |
265 | fileQuit=new QAction(tr("Quit"), tr("&Quit"), 0, this); | 279 | fileQuit=new QAction(tr("Quit"), tr("&Quit"), 0, this); |
266 | connect(fileQuit, SIGNAL(activated()), this, SLOT(close())); | 280 | connect(fileQuit, SIGNAL(activated()), this, SLOT(close())); |
267 | 281 | ||
268 | helpGeneral=new QAction(tr("General Help"), QPixmap(help_general_xpm), tr("&General"), 0, this); | 282 | helpGeneral=new QAction(tr("General Help"), QPixmap(help_general_xpm), tr("&General"), 0, this); |
269 | connect(helpGeneral, SIGNAL(activated()), this, SLOT(slotHelpGeneral())); | 283 | connect(helpGeneral, SIGNAL(activated()), this, SLOT(slotHelpGeneral())); |
270 | helpAbout=new QAction(tr("About Opie Sheet"), tr("&About"), 0, this); | 284 | helpAbout=new QAction(tr("About Opie Sheet"), tr("&About"), 0, this); |
271 | connect(helpAbout, SIGNAL(activated()), this, SLOT(slotHelpAbout())); | 285 | connect(helpAbout, SIGNAL(activated()), this, SLOT(slotHelpAbout())); |
272 | 286 | ||
273 | editAccept=new QAction(tr("Accept"), QPixmap(edit_accept_xpm), tr("&Accept"), 0, this); | 287 | editAccept=new QAction(tr("Accept"), QPixmap(edit_accept_xpm), tr("&Accept"), 0, this); |
274 | connect(editAccept, SIGNAL(activated()), this, SLOT(slotEditAccept())); | 288 | connect(editAccept, SIGNAL(activated()), this, SLOT(slotEditAccept())); |
275 | editCancel=new QAction(tr("Cancel"), QPixmap(edit_cancel_xpm), tr("&Cancel"), 0, this); | 289 | editCancel=new QAction(tr("Cancel"), QPixmap(edit_cancel_xpm), tr("&Cancel"), 0, this); |
276 | connect(editCancel, SIGNAL(activated()), this, SLOT(slotEditCancel())); | 290 | connect(editCancel, SIGNAL(activated()), this, SLOT(slotEditCancel())); |
277 | editCellSelect=new QAction(tr("Cell Selector"), QPixmap(cell_select_xpm), tr("Cell &Selector"), 0, this); | 291 | editCellSelect=new QAction(tr("Cell Selector"), QPixmap(cell_select_xpm), tr("Cell &Selector"), 0, this); |
278 | editCellSelect->setToggleAction(TRUE); | 292 | editCellSelect->setToggleAction(TRUE); |
279 | connect(editCellSelect, SIGNAL(toggled(bool)), this, SLOT(slotCellSelect(bool))); | 293 | connect(editCellSelect, SIGNAL(toggled(bool)), this, SLOT(slotCellSelect(bool))); |
280 | editCut=new QAction(tr("Cut Cells"), tr("Cu&t"), 0, this); | 294 | editCut=new QAction(tr("Cut Cells"), tr("Cu&t"), 0, this); |
281 | editCopy=new QAction(tr("Copy Cells"), tr("&Copy"), 0, this); | 295 | editCopy=new QAction(tr("Copy Cells"), tr("&Copy"), 0, this); |
282 | editPaste=new QAction(tr("Paste Cells"), tr("&Paste"), 0, this); | 296 | editPaste=new QAction(tr("Paste Cells"), tr("&Paste"), 0, this); |
283 | connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste())); | 297 | connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste())); |
284 | editPasteContents=new QAction(tr("Paste Contents"), tr("Paste Cont&ents"), 0, this); | 298 | editPasteContents=new QAction(tr("Paste Contents"), tr("Paste Cont&ents"), 0, this); |
285 | connect(editPasteContents, SIGNAL(activated()), this, SLOT(slotEditPasteContents())); | 299 | connect(editPasteContents, SIGNAL(activated()), this, SLOT(slotEditPasteContents())); |
286 | editClear=new QAction(tr("Clear Cells"), tr("C&lear"), 0, this); | 300 | editClear=new QAction(tr("Clear Cells"), tr("C&lear"), 0, this); |
287 | 301 | ||
288 | insertCells=new QAction(tr("Insert Cells"), tr("C&ells"), 0, this); | 302 | insertCells=new QAction(tr("Insert Cells"), tr("C&ells"), 0, this); |
289 | connect(insertCells, SIGNAL(activated()), this, SLOT(slotInsertCells())); | 303 | connect(insertCells, SIGNAL(activated()), this, SLOT(slotInsertCells())); |
290 | insertRows=new QAction(tr("Insert Rows"), tr("&Rows"), 0, this); | 304 | insertRows=new QAction(tr("Insert Rows"), tr("&Rows"), 0, this); |
291 | connect(insertRows, SIGNAL(activated()), this, SLOT(slotInsertRows())); | 305 | connect(insertRows, SIGNAL(activated()), this, SLOT(slotInsertRows())); |
292 | insertCols=new QAction(tr("Insert Columns"), tr("&Columns"), 0, this); | 306 | insertCols=new QAction(tr("Insert Columns"), tr("&Columns"), 0, this); |
293 | connect(insertCols, SIGNAL(activated()), this, SLOT(slotInsertCols())); | 307 | connect(insertCols, SIGNAL(activated()), this, SLOT(slotInsertCols())); |
294 | insertSheets=new QAction(tr("Add Sheets"), tr("&Sheets"), 0, this); | 308 | insertSheets=new QAction(tr("Add Sheets"), tr("&Sheets"), 0, this); |
295 | connect(insertSheets, SIGNAL(activated()), this, SLOT(slotInsertSheets())); | 309 | connect(insertSheets, SIGNAL(activated()), this, SLOT(slotInsertSheets())); |
296 | 310 | ||
297 | formatCells=new QAction(tr("Cells"), tr("&Cells"), 0, this); | 311 | formatCells=new QAction(tr("Cells"), tr("&Cells"), 0, this); |
298 | connect(formatCells, SIGNAL(activated()), this, SLOT(slotFormatCells())); | 312 | connect(formatCells, SIGNAL(activated()), this, SLOT(slotFormatCells())); |
299 | 313 | ||
300 | rowHeight=new QAction(tr("Row Height"), tr("H&eight"), 0, this); | 314 | rowHeight=new QAction(tr("Row Height"), tr("H&eight"), 0, this); |
301 | connect(rowHeight, SIGNAL(activated()), this, SLOT(slotRowHeight())); | 315 | connect(rowHeight, SIGNAL(activated()), this, SLOT(slotRowHeight())); |
302 | rowAdjust=new QAction(tr("Adjust Row"), tr("&Adjust"), 0, this); | 316 | rowAdjust=new QAction(tr("Adjust Row"), tr("&Adjust"), 0, this); |
303 | connect(rowAdjust, SIGNAL(activated()), this, SLOT(slotRowAdjust())); | 317 | connect(rowAdjust, SIGNAL(activated()), this, SLOT(slotRowAdjust())); |
304 | rowShow=new QAction(tr("Show Row"), tr("&Show"), 0, this); | 318 | rowShow=new QAction(tr("Show Row"), tr("&Show"), 0, this); |
305 | connect(rowShow, SIGNAL(activated()), this, SLOT(slotRowShow())); | 319 | connect(rowShow, SIGNAL(activated()), this, SLOT(slotRowShow())); |
306 | rowHide=new QAction(tr("Hide Row"), tr("&Hide"), 0, this); | 320 | rowHide=new QAction(tr("Hide Row"), tr("&Hide"), 0, this); |
307 | connect(rowHide, SIGNAL(activated()), this, SLOT(slotRowHide())); | 321 | connect(rowHide, SIGNAL(activated()), this, SLOT(slotRowHide())); |
308 | 322 | ||
309 | colWidth=new QAction(tr("Column Width"), tr("&Width"), 0, this); | 323 | colWidth=new QAction(tr("Column Width"), tr("&Width"), 0, this); |
310 | connect(colWidth, SIGNAL(activated()), this, SLOT(slotColumnWidth())); | 324 | connect(colWidth, SIGNAL(activated()), this, SLOT(slotColumnWidth())); |
311 | colAdjust=new QAction(tr("Adjust Column"), tr("&Adjust"), 0, this); | 325 | colAdjust=new QAction(tr("Adjust Column"), tr("&Adjust"), 0, this); |
312 | connect(colAdjust, SIGNAL(activated()), this, SLOT(slotColumnAdjust())); | 326 | connect(colAdjust, SIGNAL(activated()), this, SLOT(slotColumnAdjust())); |
313 | colShow=new QAction(tr("Show Column"), tr("&Show"), 0, this); | 327 | colShow=new QAction(tr("Show Column"), tr("&Show"), 0, this); |
314 | connect(colShow, SIGNAL(activated()), this, SLOT(slotColumnShow())); | 328 | connect(colShow, SIGNAL(activated()), this, SLOT(slotColumnShow())); |
315 | colHide=new QAction(tr("Hide Column"), tr("&Hide"), 0, this); | 329 | colHide=new QAction(tr("Hide Column"), tr("&Hide"), 0, this); |
316 | connect(colHide, SIGNAL(activated()), this, SLOT(slotColumnHide())); | 330 | connect(colHide, SIGNAL(activated()), this, SLOT(slotColumnHide())); |
317 | 331 | ||
318 | sheetRename=new QAction(tr("Rename Sheet"), tr("&Rename"), 0, this); | 332 | sheetRename=new QAction(tr("Rename Sheet"), tr("&Rename"), 0, this); |
319 | connect(sheetRename, SIGNAL(activated()), this, SLOT(slotSheetRename())); | 333 | connect(sheetRename, SIGNAL(activated()), this, SLOT(slotSheetRename())); |
320 | sheetRemove=new QAction(tr("Remove Sheet"), tr("R&emove"), 0, this); | 334 | sheetRemove=new QAction(tr("Remove Sheet"), tr("R&emove"), 0, this); |
321 | connect(sheetRemove, SIGNAL(activated()), this, SLOT(slotSheetRemove())); | 335 | connect(sheetRemove, SIGNAL(activated()), this, SLOT(slotSheetRemove())); |
322 | 336 | ||
323 | dataSort=new QAction(tr("Sort Data"), tr("&Sort"), 0, this); | 337 | dataSort=new QAction(tr("Sort Data"), tr("&Sort"), 0, this); |
324 | connect(dataSort, SIGNAL(activated()), this, SLOT(slotDataSort())); | 338 | connect(dataSort, SIGNAL(activated()), this, SLOT(slotDataSort())); |
325 | dataFindReplace=new QAction(tr("Find && Replace"), tr("&Find && Replace"), 0, this); | 339 | dataFindReplace=new QAction(tr("Find && Replace"), tr("&Find && Replace"), 0, this); |
326 | connect(dataFindReplace, SIGNAL(activated()), this, SLOT(slotDataFindReplace())); | 340 | connect(dataFindReplace, SIGNAL(activated()), this, SLOT(slotDataFindReplace())); |
327 | 341 | ||
328 | funcEqual=new QAction(tr("Equal To"), QPixmap(func_equal_xpm), tr("&Equal To"), 0, this); | 342 | funcEqual=new QAction(tr("Equal To"), QPixmap(func_equal_xpm), tr("&Equal To"), 0, this); |
329 | funcEqual->setToolTip("="); | 343 | funcEqual->setToolTip("="); |
330 | connect(funcEqual, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 344 | connect(funcEqual, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
331 | funcPlus=new QAction(tr("Addition"), QPixmap(func_plus_xpm), tr("&Addition"), 0, this); | 345 | funcPlus=new QAction(tr("Addition"), QPixmap(func_plus_xpm), tr("&Addition"), 0, this); |
332 | funcPlus->setToolTip("+"); | 346 | funcPlus->setToolTip("+"); |
333 | connect(funcPlus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 347 | connect(funcPlus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
334 | funcMinus=new QAction(tr("Subtraction"), QPixmap(func_minus_xpm), tr("&Subtraction"), 0, this); | 348 | funcMinus=new QAction(tr("Subtraction"), QPixmap(func_minus_xpm), tr("&Subtraction"), 0, this); |
335 | funcMinus->setToolTip("-"); | 349 | funcMinus->setToolTip("-"); |
336 | connect(funcMinus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 350 | connect(funcMinus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
337 | funcCross=new QAction(tr("Multiplication"), QPixmap(func_cross_xpm), tr("&Multiplication"), 0, this); | 351 | funcCross=new QAction(tr("Multiplication"), QPixmap(func_cross_xpm), tr("&Multiplication"), 0, this); |
338 | funcCross->setToolTip("*"); | 352 | funcCross->setToolTip("*"); |
339 | connect(funcCross, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 353 | connect(funcCross, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
340 | funcDivide=new QAction(tr("Division"), QPixmap(func_divide_xpm), tr("&Division"), 0, this); | 354 | funcDivide=new QAction(tr("Division"), QPixmap(func_divide_xpm), tr("&Division"), 0, this); |
341 | funcDivide->setToolTip("/"); | 355 | funcDivide->setToolTip("/"); |
342 | connect(funcDivide, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 356 | connect(funcDivide, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
343 | funcParanOpen=new QAction(tr("Open ParanthesistempCellData->row+row1, tempCellData->col+col1"), QPixmap(func_paran_open_xpm), tr("&Open Paranthesis"), 0, this); | 357 | funcParanOpen=new QAction(tr("Open ParanthesistempCellData->row+row1, tempCellData->col+col1"), QPixmap(func_paran_open_xpm), tr("&Open Paranthesis"), 0, this); |
344 | funcParanOpen->setToolTip("("); | 358 | funcParanOpen->setToolTip("("); |
345 | connect(funcParanOpen, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 359 | connect(funcParanOpen, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
346 | funcParanClose=new QAction(tr("Close Paranthesis"), QPixmap(func_paran_close_xpm), tr("&Close Paranthesis"), 0, this); | 360 | funcParanClose=new QAction(tr("Close Paranthesis"), QPixmap(func_paran_close_xpm), tr("&Close Paranthesis"), 0, this); |
347 | funcParanClose->setToolTip(")"); | 361 | funcParanClose->setToolTip(")"); |
348 | connect(funcParanClose, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 362 | connect(funcParanClose, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
349 | funcComma=new QAction(tr("Comma"), QPixmap(func_comma_xpm), tr("&Comma"), 0, this); | 363 | funcComma=new QAction(tr("Comma"), QPixmap(func_comma_xpm), tr("&Comma"), 0, this); |
350 | funcComma->setToolTip(","); | 364 | funcComma->setToolTip(","); |
351 | connect(funcComma, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 365 | connect(funcComma, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
352 | } | 366 | } |
353 | 367 | ||
354 | void MainWindow::initMenu() | 368 | void MainWindow::initMenu() |
355 | { | 369 | { |
356 | menu=new QPEMenuBar(this); | 370 | menu=new QPEMenuBar(this); |
357 | 371 | ||
358 | menuFile=new QPopupMenu; | 372 | menuFile=new QPopupMenu; |
359 | fileNew->addTo(menuFile); | 373 | fileNew->addTo(menuFile); |
360 | fileOpen->addTo(menuFile); | 374 | fileOpen->addTo(menuFile); |
361 | fileSave->addTo(menuFile); | 375 | fileSave->addTo(menuFile); |
362 | fileSaveAs->addTo(menuFile); | 376 | fileSaveAs->addTo(menuFile); |
363 | menuFile->insertSeparator(); | 377 | menuFile->insertSeparator(); |
364 | fileQuit->addTo(menuFile); | 378 | fileQuit->addTo(menuFile); |
365 | menu->insertItem(tr("&File"), menuFile); | 379 | menu->insertItem(tr("&File"), menuFile); |
366 | 380 | ||
367 | menuEdit=new QPopupMenu; | 381 | menuEdit=new QPopupMenu; |
368 | editAccept->addTo(menuEdit); | 382 | editAccept->addTo(menuEdit); |
369 | editCancel->addTo(menuEdit); | 383 | editCancel->addTo(menuEdit); |
370 | editCellSelect->addTo(menuEdit); | 384 | editCellSelect->addTo(menuEdit); |
371 | menuEdit->insertSeparator(); | 385 | menuEdit->insertSeparator(); |
372 | editCut->addTo(menuEdit); | 386 | editCut->addTo(menuEdit); |
373 | editCopy->addTo(menuEdit); | 387 | editCopy->addTo(menuEdit); |
374 | editPaste->addTo(menuEdit); | 388 | editPaste->addTo(menuEdit); |
375 | editPasteContents->addTo(menuEdit); | 389 | editPasteContents->addTo(menuEdit); |
376 | editClear->addTo(menuEdit); | 390 | editClear->addTo(menuEdit); |
377 | menu->insertItem(tr("&Edit"), menuEdit); | 391 | menu->insertItem(tr("&Edit"), menuEdit); |
378 | 392 | ||
379 | menuInsert=new QPopupMenu; | 393 | menuInsert=new QPopupMenu; |
380 | menu->insertItem(tr("&Insert"), menuInsert); | 394 | menu->insertItem(tr("&Insert"), menuInsert); |
381 | 395 | ||
382 | menuFormat=new QPopupMenu; | 396 | menuFormat=new QPopupMenu; |
383 | formatCells->addTo(menuFormat); | 397 | formatCells->addTo(menuFormat); |
384 | menu->insertItem(tr("&Format"), menuFormat); | 398 | menu->insertItem(tr("&Format"), menuFormat); |
385 | 399 | ||
386 | menuData=new QPopupMenu; | 400 | menuData=new QPopupMenu; |
387 | dataSort->addTo(menuData); | 401 | dataSort->addTo(menuData); |
388 | dataFindReplace->addTo(menuData); | 402 | dataFindReplace->addTo(menuData); |
389 | menu->insertItem(tr("&Data"), menuData); | 403 | menu->insertItem(tr("&Data"), menuData); |
390 | 404 | ||
391 | menuHelp=new QPopupMenu; | 405 | menuHelp=new QPopupMenu; |
392 | helpGeneral->addTo(menuHelp); | 406 | helpGeneral->addTo(menuHelp); |
393 | helpAbout->addTo(menuHelp); | 407 | helpAbout->addTo(menuHelp); |
394 | menu->insertItem(tr("&Help"), menuHelp); | 408 | menu->insertItem(tr("&Help"), menuHelp); |
395 | 409 | ||
396 | submenuRow=new QPopupMenu; | 410 | submenuRow=new QPopupMenu; |
397 | rowHeight->addTo(submenuRow); | 411 | rowHeight->addTo(submenuRow); |
398 | rowAdjust->addTo(submenuRow); | 412 | rowAdjust->addTo(submenuRow); |
399 | rowShow->addTo(submenuRow); | 413 | rowShow->addTo(submenuRow); |
400 | rowHide->addTo(submenuRow); | 414 | rowHide->addTo(submenuRow); |
401 | menuFormat->insertItem(tr("&Row"), submenuRow); | 415 | menuFormat->insertItem(tr("&Row"), submenuRow); |
402 | 416 | ||
403 | submenuCol=new QPopupMenu; | 417 | submenuCol=new QPopupMenu; |
404 | colWidth->addTo(submenuCol); | 418 | colWidth->addTo(submenuCol); |
405 | colAdjust->addTo(submenuCol); | 419 | colAdjust->addTo(submenuCol); |
406 | colShow->addTo(submenuCol); | 420 | colShow->addTo(submenuCol); |
407 | colHide->addTo(submenuCol); | 421 | colHide->addTo(submenuCol); |
408 | menuFormat->insertItem(tr("Colum&n"), submenuCol); | 422 | menuFormat->insertItem(tr("Colum&n"), submenuCol); |
409 | 423 | ||
410 | submenuSheet=new QPopupMenu; | 424 | submenuSheet=new QPopupMenu; |
411 | sheetRename->addTo(submenuSheet); | 425 | sheetRename->addTo(submenuSheet); |
412 | sheetRemove->addTo(submenuSheet); | 426 | sheetRemove->addTo(submenuSheet); |
413 | menuFormat->insertItem(tr("&Sheet"), submenuSheet); | 427 | menuFormat->insertItem(tr("&Sheet"), submenuSheet); |
414 | 428 | ||
415 | submenuFunc=new QPopupMenu; | 429 | submenuFunc=new QPopupMenu; |
416 | menuInsert->insertItem(tr("&Function"), submenuFunc); | 430 | menuInsert->insertItem(tr("&Function"), submenuFunc); |
417 | 431 | ||
418 | submenuFuncStd=new QPopupMenu; | 432 | submenuFuncStd=new QPopupMenu; |
419 | funcPlus->addTo(submenuFuncStd); | 433 | funcPlus->addTo(submenuFuncStd); |
420 | funcMinus->addTo(submenuFuncStd); | 434 | funcMinus->addTo(submenuFuncStd); |
421 | funcCross->addTo(submenuFuncStd); | 435 | funcCross->addTo(submenuFuncStd); |
422 | funcDivide->addTo(submenuFuncStd); | 436 | funcDivide->addTo(submenuFuncStd); |
423 | submenuFunc->insertItem(tr("&Standard"), submenuFuncStd); | 437 | submenuFunc->insertItem(tr("&Standard"), submenuFuncStd); |
424 | 438 | ||
425 | submenuFuncMath=new QPopupMenu; | 439 | submenuFuncMath=new QPopupMenu; |
426 | addFlyAction(tr("Summation"), tr("&Summation"), "SUM(", submenuFuncMath); | 440 | addFlyAction(tr("Summation"), tr("&Summation"), "SUM(", submenuFuncMath); |
427 | addFlyAction(tr("Absolute Value"), tr("&Absolute"), "ABS(", submenuFuncMath); | 441 | addFlyAction(tr("Absolute Value"), tr("&Absolute"), "ABS(", submenuFuncMath); |
428 | submenuFuncMath->insertSeparator(); | 442 | submenuFuncMath->insertSeparator(); |
429 | addFlyAction(tr("Sine"), tr("Si&ne"), "SIN(", submenuFuncMath); | 443 | addFlyAction(tr("Sine"), tr("Si&ne"), "SIN(", submenuFuncMath); |
430 | addFlyAction(tr("Arc Sine"), tr("A&rc Sine"), "ASIN(", submenuFuncMath); | 444 | addFlyAction(tr("Arc Sine"), tr("A&rc Sine"), "ASIN(", submenuFuncMath); |
431 | addFlyAction(tr("Cosine"), tr("&Cosine"), "COS(", submenuFuncMath); | 445 | addFlyAction(tr("Cosine"), tr("&Cosine"), "COS(", submenuFuncMath); |
432 | addFlyAction(tr("ArcCosine"), tr("Arc Cos&ine"), "COS(", submenuFuncMath); | 446 | addFlyAction(tr("ArcCosine"), tr("Arc Cos&ine"), "COS(", submenuFuncMath); |
433 | addFlyAction(tr("Tangent"), tr("&Tangent"), "TAN(", submenuFuncMath); | 447 | addFlyAction(tr("Tangent"), tr("&Tangent"), "TAN(", submenuFuncMath); |
434 | addFlyAction(tr("Arc Tangent"), tr("Arc Tan&gent"), "ATAN(", submenuFuncMath); | 448 | addFlyAction(tr("Arc Tangent"), tr("Arc Tan&gent"), "ATAN(", submenuFuncMath); |
435 | addFlyAction(tr("Arc Tangent of Coordinates"), tr("C&oor. Arc Tangent"), "ATAN2(", submenuFuncMath); | 449 | addFlyAction(tr("Arc Tangent of Coordinates"), tr("C&oor. Arc Tangent"), "ATAN2(", submenuFuncMath); |
436 | submenuFuncMath->insertSeparator(); | 450 | submenuFuncMath->insertSeparator(); |
437 | addFlyAction(tr("Exponential"), tr("&Exponential"), "EXP(", submenuFuncMath); | 451 | addFlyAction(tr("Exponential"), tr("&Exponential"), "EXP(", submenuFuncMath); |
438 | addFlyAction(tr("Logarithm"), tr("&Logarithm"), "LOG(", submenuFuncMath); | 452 | addFlyAction(tr("Logarithm"), tr("&Logarithm"), "LOG(", submenuFuncMath); |
439 | addFlyAction(tr("Power"), tr("&Power"), "POW(", submenuFuncMath); | 453 | addFlyAction(tr("Power"), tr("&Power"), "POW(", submenuFuncMath); |
440 | submenuFunc->insertItem(tr("&Mathematical"), submenuFuncMath); | 454 | submenuFunc->insertItem(tr("&Mathematical"), submenuFuncMath); |
441 | 455 | ||
442 | submenuFuncStat=new QPopupMenu; | 456 | submenuFuncStat=new QPopupMenu; |
443 | addFlyAction(tr("Average"), tr("&Average"), "AVG(", submenuFuncStat); | 457 | addFlyAction(tr("Average"), tr("&Average"), "AVG(", submenuFuncStat); |
444 | addFlyAction(tr("Maximum"), tr("Ma&ximum"), "MAX(", submenuFuncStat); | 458 | addFlyAction(tr("Maximum"), tr("Ma&ximum"), "MAX(", submenuFuncStat); |
445 | addFlyAction(tr("Minimum"), tr("&Minimum"), "MIN(", submenuFuncStat); | 459 | addFlyAction(tr("Minimum"), tr("&Minimum"), "MIN(", submenuFuncStat); |
446 | addFlyAction(tr("Count"), tr("&Count"), "COUNT(", submenuFuncStat); | 460 | addFlyAction(tr("Count"), tr("&Count"), "COUNT(", submenuFuncStat); |
447 | submenuFunc->insertItem(tr("&Statistical"), submenuFuncStat); | 461 | submenuFunc->insertItem(tr("&Statistical"), submenuFuncStat); |
448 | 462 | ||
449 | menuInsert->insertSeparator(); | 463 | menuInsert->insertSeparator(); |
450 | insertCells->addTo(menuInsert); | 464 | insertCells->addTo(menuInsert); |
451 | insertRows->addTo(menuInsert); | 465 | insertRows->addTo(menuInsert); |
452 | insertCols->addTo(menuInsert); | 466 | insertCols->addTo(menuInsert); |
453 | insertSheets->addTo(menuInsert); | 467 | insertSheets->addTo(menuInsert); |
454 | } | 468 | } |
455 | 469 | ||
456 | void MainWindow::initStandardToolbar() | 470 | void MainWindow::initStandardToolbar() |
457 | { | 471 | { |
458 | toolbarStandard=new QPEToolBar(this); | 472 | toolbarStandard=new QPEToolBar(this); |
459 | toolbarStandard->setHorizontalStretchable(TRUE); | 473 | toolbarStandard->setHorizontalStretchable(TRUE); |
460 | moveToolBar(toolbarStandard, Top); | 474 | moveToolBar(toolbarStandard, Top); |
461 | 475 | ||
462 | fileNew->addTo(toolbarStandard); | 476 | fileNew->addTo(toolbarStandard); |
463 | fileOpen->addTo(toolbarStandard); | 477 | fileOpen->addTo(toolbarStandard); |
464 | fileSave->addTo(toolbarStandard); | 478 | fileSave->addTo(toolbarStandard); |
465 | 479 | ||
466 | comboSheets=new QComboBox(toolbarStandard); | 480 | comboSheets=new QComboBox(toolbarStandard); |
467 | toolbarStandard->setStretchableWidget(comboSheets); | 481 | toolbarStandard->setStretchableWidget(comboSheets); |
468 | connect(comboSheets, SIGNAL(activated(const QString &)), this, SLOT(slotSheetChanged(const QString &))); | 482 | connect(comboSheets, SIGNAL(activated(const QString &)), this, SLOT(slotSheetChanged(const QString &))); |
469 | } | 483 | } |
470 | 484 | ||
471 | void MainWindow::initFunctionsToolbar() | 485 | void MainWindow::initFunctionsToolbar() |
472 | { | 486 | { |
473 | toolbarFunctions=new QPEToolBar(this); | 487 | toolbarFunctions=new QPEToolBar(this); |
474 | toolbarFunctions->setHorizontalStretchable(TRUE); | 488 | toolbarFunctions->setHorizontalStretchable(TRUE); |
475 | moveToolBar(toolbarFunctions, Bottom); | 489 | moveToolBar(toolbarFunctions, Bottom); |
476 | 490 | ||
477 | funcEqual->addTo(toolbarFunctions); | 491 | funcEqual->addTo(toolbarFunctions); |
478 | funcPlus->addTo(toolbarFunctions); | 492 | funcPlus->addTo(toolbarFunctions); |
479 | funcMinus->addTo(toolbarFunctions); | 493 | funcMinus->addTo(toolbarFunctions); |
480 | funcCross->addTo(toolbarFunctions); | 494 | funcCross->addTo(toolbarFunctions); |
481 | funcDivide->addTo(toolbarFunctions); | 495 | funcDivide->addTo(toolbarFunctions); |
482 | funcParanOpen->addTo(toolbarFunctions); | 496 | funcParanOpen->addTo(toolbarFunctions); |
483 | funcParanClose->addTo(toolbarFunctions); | 497 | funcParanClose->addTo(toolbarFunctions); |
484 | funcComma->addTo(toolbarFunctions); | 498 | funcComma->addTo(toolbarFunctions); |
485 | 499 | ||
486 | toolFunction=new QToolButton(toolbarFunctions); | 500 | toolFunction=new QToolButton(toolbarFunctions); |
487 | toolFunction->setPixmap(func_func_xpm); | 501 | toolFunction->setPixmap(func_func_xpm); |
488 | toolFunction->setTextLabel(tr("Functions")); | 502 | toolFunction->setTextLabel(tr("Functions")); |
489 | toolFunction->setPopup(submenuFunc); | 503 | toolFunction->setPopup(submenuFunc); |
490 | toolFunction->setPopupDelay(0); | 504 | toolFunction->setPopupDelay(0); |
491 | } | 505 | } |
492 | 506 | ||
493 | void MainWindow::initEditToolbar() | 507 | void MainWindow::initEditToolbar() |
494 | { | 508 | { |
495 | toolbarEdit=new QPEToolBar(this); | 509 | toolbarEdit=new QPEToolBar(this); |
496 | toolbarEdit->setHorizontalStretchable(TRUE); | 510 | toolbarEdit->setHorizontalStretchable(TRUE); |
497 | moveToolBar(toolbarEdit, Bottom); | 511 | moveToolBar(toolbarEdit, Bottom); |
498 | 512 | ||
499 | editAccept->addTo(toolbarEdit); | 513 | editAccept->addTo(toolbarEdit); |
500 | editCancel->addTo(toolbarEdit); | 514 | editCancel->addTo(toolbarEdit); |
501 | 515 | ||
502 | editData=new QLineEdit(toolbarEdit); | 516 | editData=new QLineEdit(toolbarEdit); |
503 | toolbarEdit->setStretchableWidget(editData); | 517 | toolbarEdit->setStretchableWidget(editData); |
504 | connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept())); | 518 | connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept())); |
505 | 519 | ||
506 | editCellSelect->addTo(toolbarEdit); | 520 | editCellSelect->addTo(toolbarEdit); |
507 | } | 521 | } |
508 | 522 | ||
509 | void MainWindow::slotHelpGeneral() | 523 | void MainWindow::slotHelpGeneral() |
510 | { | 524 | { |
511 | if (QFile::exists(helpFile)) | 525 | if (QFile::exists(helpFile)) |
512 | { | 526 | { |
513 | QCopEnvelope e("QPE/Application/helpbrowser", "showFile(QString)"); | 527 | QCopEnvelope e("QPE/Application/helpbrowser", "showFile(QString)"); |
514 | e << helpFile; | 528 | e << helpFile; |
515 | } | 529 | } |
516 | else | 530 | else |
517 | QMessageBox::critical(this, tr("Error"), tr("Help file not found!")); | 531 | QMessageBox::critical(this, tr("Error"), tr("Help file not found!")); |
518 | } | 532 | } |
519 | 533 | ||
520 | void MainWindow::slotHelpAbout() | 534 | void MainWindow::slotHelpAbout() |
521 | { | 535 | { |
522 | QDialog dialogAbout(this, 0, TRUE); | 536 | QDialog dialogAbout(this, 0, TRUE); |
523 | dialogAbout.resize(width()-40, height()-80); | 537 | dialogAbout.resize(width()-40, height()-80); |
524 | dialogAbout.setCaption(tr("About Opie Sheet")); | 538 | dialogAbout.setCaption(tr("About Opie Sheet")); |
525 | 539 | ||
526 | QLabel label(tr("Opie Sheet\nSpreadsheet Software for Opie\nQWDC Beta Winner (as Sheet/Qt)\n\nDeveloped by: Serdar Ozler\nVersion: 1.0.1 (Final)\nRelease Date: July 4, 2002\n\nThis product is licensed under GPL. It is freely distributable. If you want to get the latest version and also the source code, please visit the web site.\n\nhttp://qtopia.sitebest.com"), &dialogAbout); | 540 | QLabel label(tr("Opie Sheet\nSpreadsheet Software for Opie\nQWDC Beta Winner (as Sheet/Qt)\n\nDeveloped by: Serdar Ozler\nVersion: 1.0.1 (Final)\nRelease Date: July 4, 2002\n\nThis product is licensed under GPL. It is freely distributable. If you want to get the latest version and also the source code, please visit the web site.\n\nhttp://qtopia.sitebest.com"), &dialogAbout); |
527 | label.setGeometry(dialogAbout.rect()); | 541 | label.setGeometry(dialogAbout.rect()); |
528 | label.setAlignment(Qt::AlignCenter | Qt::WordBreak); | 542 | label.setAlignment(Qt::AlignCenter | Qt::WordBreak); |
529 | 543 | ||
530 | dialogAbout.exec(); | 544 | dialogAbout.exec(); |
531 | } | 545 | } |
532 | 546 | ||
533 | void MainWindow::initSheet() | 547 | void MainWindow::initSheet() |
534 | { | 548 | { |
535 | sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this); | 549 | sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this); |
536 | setCentralWidget(sheet); | 550 | setCentralWidget(sheet); |
537 | 551 | ||
538 | connect(sheet, SIGNAL(currentDataChanged(const QString &)), editData, SLOT(setText(const QString &))); | 552 | connect(sheet, SIGNAL(currentDataChanged(const QString &)), editData, SLOT(setText(const QString &))); |
539 | connect(sheet, SIGNAL(cellClicked(const QString &)), this, SLOT(slotCellClicked(const QString &))); | 553 | connect(sheet, SIGNAL(cellClicked(const QString &)), this, SLOT(slotCellClicked(const QString &))); |
540 | connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified())); | 554 | connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified())); |
541 | 555 | ||
542 | connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut())); | 556 | connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut())); |
543 | connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy())); | 557 | connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy())); |
544 | connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear())); | 558 | connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear())); |
545 | } | 559 | } |
546 | 560 | ||
547 | void MainWindow::slotEditAccept() | 561 | void MainWindow::slotEditAccept() |
548 | { | 562 | { |
549 | sheet->setData(editData->text()); | 563 | sheet->setData(editData->text()); |
550 | } | 564 | } |
551 | 565 | ||
552 | void MainWindow::slotEditCancel() | 566 | void MainWindow::slotEditCancel() |
553 | { | 567 | { |
554 | editData->setText(sheet->getData()); | 568 | editData->setText(sheet->getData()); |
555 | } | 569 | } |
556 | 570 | ||
557 | void MainWindow::slotCellSelect(bool lock) | 571 | void MainWindow::slotCellSelect(bool lock) |
558 | { | 572 | { |
559 | sheet->lockClicks(lock); | 573 | sheet->lockClicks(lock); |
560 | } | 574 | } |
561 | 575 | ||
562 | void MainWindow::addToData(const QString &data) | 576 | void MainWindow::addToData(const QString &data) |
563 | { | 577 | { |
564 | editData->setText(editData->text().insert(editData->cursorPosition(), data)); | 578 | editData->setText(editData->text().insert(editData->cursorPosition(), data)); |
565 | } | 579 | } |
566 | 580 | ||
567 | void MainWindow::slotFuncOutput() | 581 | void MainWindow::slotFuncOutput() |
568 | { | 582 | { |
569 | if (sender()->isA("QAction")) | 583 | if (sender()->isA("QAction")) |
570 | addToData(((QAction *)sender())->toolTip()); | 584 | addToData(((QAction *)sender())->toolTip()); |
571 | } | 585 | } |
572 | 586 | ||
573 | void MainWindow::slotInsertRows() | 587 | void MainWindow::slotInsertRows() |
574 | { | 588 | { |
575 | NumberDialog dialogNumber(this); | 589 | NumberDialog dialogNumber(this); |
576 | if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted) | 590 | if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted) |
577 | sheet->insertRows(dialogNumber.getValue()); | 591 | sheet->insertRows(dialogNumber.getValue()); |
578 | } | 592 | } |
579 | 593 | ||
580 | void MainWindow::slotInsertCols() | 594 | void MainWindow::slotInsertCols() |
581 | { | 595 | { |
582 | NumberDialog dialogNumber(this); | 596 | NumberDialog dialogNumber(this); |
583 | if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted) | 597 | if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted) |
584 | sheet->insertColumns(dialogNumber.getValue()); | 598 | sheet->insertColumns(dialogNumber.getValue()); |
585 | } | 599 | } |
586 | 600 | ||
587 | void MainWindow::slotInsertSheets() | 601 | void MainWindow::slotInsertSheets() |
588 | { | 602 | { |
589 | NumberDialog dialogNumber(this); | 603 | NumberDialog dialogNumber(this); |
590 | if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted) | 604 | if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted) |
591 | for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet(); | 605 | for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet(); |
592 | } | 606 | } |
593 | 607 | ||
594 | void MainWindow::slotCellClicked(const QString &cell) | 608 | void MainWindow::slotCellClicked(const QString &cell) |
595 | { | 609 | { |
596 | editCellSelect->setOn(FALSE); | 610 | editCellSelect->setOn(FALSE); |
597 | addToData(cell); | 611 | addToData(cell); |
598 | } | 612 | } |
599 | 613 | ||
600 | typeSheet *MainWindow::createNewSheet() | 614 | typeSheet *MainWindow::createNewSheet() |
601 | { | 615 | { |
602 | typeSheet *newSheet=new typeSheet; | 616 | typeSheet *newSheet=new typeSheet; |
603 | int currentNo=1, tempNo; | 617 | int currentNo=1, tempNo; |
604 | bool ok; | 618 | bool ok; |
605 | 619 | ||
606 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) | 620 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) |
607 | if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok) | 621 | if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok) |
608 | currentNo=tempNo+1; | 622 | currentNo=tempNo+1; |
609 | 623 | ||
610 | newSheet->name=tr("Sheet")+QString::number(currentNo); | 624 | newSheet->name=tr("Sheet")+QString::number(currentNo); |
611 | newSheet->data.setAutoDelete(TRUE); | 625 | newSheet->data.setAutoDelete(TRUE); |
612 | 626 | ||
613 | comboSheets->insertItem(newSheet->name); | 627 | comboSheets->insertItem(newSheet->name); |
614 | listSheets.append(newSheet); | 628 | listSheets.append(newSheet); |
615 | return newSheet; | 629 | return newSheet; |
616 | } | 630 | } |
617 | 631 | ||
618 | typeSheet *MainWindow::findSheet(const QString &name) | 632 | typeSheet *MainWindow::findSheet(const QString &name) |
619 | { | 633 | { |
620 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) | 634 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) |
621 | if (tempSheet->name==name) | 635 | if (tempSheet->name==name) |
622 | return tempSheet; | 636 | return tempSheet; |
623 | return NULL; | 637 | return NULL; |
624 | } | 638 | } |
625 | 639 | ||
626 | void MainWindow::slotSheetChanged(const QString &name) | 640 | void MainWindow::slotSheetChanged(const QString &name) |
627 | { | 641 | { |
628 | sheet->copySheetData(&findSheet(sheet->getName())->data); | 642 | sheet->copySheetData(&findSheet(sheet->getName())->data); |
629 | sheet->setName(name); | 643 | sheet->setName(name); |
630 | sheet->setSheetData(&findSheet(name)->data); | 644 | sheet->setSheetData(&findSheet(name)->data); |
631 | } | 645 | } |
632 | 646 | ||
633 | void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w) | 647 | void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w) |
634 | { | 648 | { |
635 | QAction *action=new QAction(text, menuText, 0, this); | 649 | QAction *action=new QAction(text, menuText, 0, this); |
636 | action->setToolTip(tip); | 650 | action->setToolTip(tip); |
637 | connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 651 | connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
638 | action->addTo(w); | 652 | action->addTo(w); |
639 | } | 653 | } |
640 | 654 | ||
641 | void MainWindow::slotFormatCells() | 655 | void MainWindow::slotFormatCells() |
642 | { | 656 | { |
643 | CellFormat dialogCellFormat(this); | 657 | CellFormat dialogCellFormat(this); |
644 | dialogCellFormat.showMaximized(); | 658 | dialogCellFormat.showMaximized(); |
645 | dialogCellFormat.exec(sheet); | 659 | dialogCellFormat.exec(sheet); |
646 | } | 660 | } |
647 | 661 | ||
648 | void MainWindow::slotEditPaste() | 662 | void MainWindow::slotEditPaste() |
649 | { | 663 | { |
650 | sheet->editPaste(); | 664 | sheet->editPaste(); |
651 | } | 665 | } |
652 | 666 | ||
653 | void MainWindow::slotEditPasteContents() | 667 | void MainWindow::slotEditPasteContents() |
654 | { | 668 | { |
655 | sheet->editPaste(TRUE); | 669 | sheet->editPaste(TRUE); |
656 | } | 670 | } |
657 | 671 | ||
658 | void MainWindow::slotRowHeight() | 672 | void MainWindow::slotRowHeight() |
659 | { | 673 | { |
660 | int row1, row2, col1, col2; | 674 | int row1, row2, col1, col2; |
661 | sheet->getSelection(&row1, &col1, &row2, &col2); | 675 | sheet->getSelection(&row1, &col1, &row2, &col2); |
662 | 676 | ||
663 | NumberDialog dialogNumber(this); | 677 | NumberDialog dialogNumber(this); |
664 | if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted) | 678 | if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted) |
665 | { | 679 | { |
666 | int newHeight=dialogNumber.getValue(), row; | 680 | int newHeight=dialogNumber.getValue(), row; |
667 | for (row=row1; row<=row2; ++row) | 681 | for (row=row1; row<=row2; ++row) |
668 | sheet->setRowHeight(row, newHeight); | 682 | sheet->setRowHeight(row, newHeight); |
669 | } | 683 | } |
670 | } | 684 | } |
671 | 685 | ||
672 | void MainWindow::slotRowAdjust() | 686 | void MainWindow::slotRowAdjust() |
673 | { | 687 | { |
674 | int row1, row2, col1, col2; | 688 | int row1, row2, col1, col2; |
675 | sheet->getSelection(&row1, &col1, &row2, &col2); | 689 | sheet->getSelection(&row1, &col1, &row2, &col2); |
676 | 690 | ||
677 | for (int row=row1; row<=row2; ++row) | 691 | for (int row=row1; row<=row2; ++row) |
678 | sheet->adjustRow(row); | 692 | sheet->adjustRow(row); |
679 | } | 693 | } |
680 | 694 | ||
681 | void MainWindow::slotRowShow() | 695 | void MainWindow::slotRowShow() |
682 | { | 696 | { |
683 | int row1, row2, col1, col2; | 697 | int row1, row2, col1, col2; |
684 | sheet->getSelection(&row1, &col1, &row2, &col2); | 698 | sheet->getSelection(&row1, &col1, &row2, &col2); |
685 | 699 | ||
686 | for (int row=row1; row<=row2; ++row) | 700 | for (int row=row1; row<=row2; ++row) |
687 | sheet->showRow(row); | 701 | sheet->showRow(row); |
688 | } | 702 | } |
689 | 703 | ||
690 | void MainWindow::slotRowHide() | 704 | void MainWindow::slotRowHide() |
691 | { | 705 | { |
692 | int row1, row2, col1, col2; | 706 | int row1, row2, col1, col2; |
693 | sheet->getSelection(&row1, &col1, &row2, &col2); | 707 | sheet->getSelection(&row1, &col1, &row2, &col2); |
694 | 708 | ||
695 | for (int row=row1; row<=row2; ++row) | 709 | for (int row=row1; row<=row2; ++row) |
696 | sheet->hideRow(row); | 710 | sheet->hideRow(row); |
697 | } | 711 | } |
698 | 712 | ||
699 | void MainWindow::slotColumnWidth() | 713 | void MainWindow::slotColumnWidth() |
700 | { | 714 | { |
701 | int row1, row2, col1, col2; | 715 | int row1, row2, col1, col2; |
702 | sheet->getSelection(&row1, &col1, &row2, &col2); | 716 | sheet->getSelection(&row1, &col1, &row2, &col2); |
703 | 717 | ||
704 | NumberDialog dialogNumber(this); | 718 | NumberDialog dialogNumber(this); |
705 | if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted) | 719 | if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted) |
706 | { | 720 | { |
707 | int newWidth=dialogNumber.getValue(), col; | 721 | int newWidth=dialogNumber.getValue(), col; |
708 | for (col=col1; col<=col2; ++col) | 722 | for (col=col1; col<=col2; ++col) |
709 | sheet->setColumnWidth(col, newWidth); | 723 | sheet->setColumnWidth(col, newWidth); |
710 | } | 724 | } |
711 | } | 725 | } |
712 | 726 | ||
713 | void MainWindow::slotColumnAdjust() | 727 | void MainWindow::slotColumnAdjust() |
714 | { | 728 | { |
715 | int row1, row2, col1, col2; | 729 | int row1, row2, col1, col2; |
716 | sheet->getSelection(&row1, &col1, &row2, &col2); | 730 | sheet->getSelection(&row1, &col1, &row2, &col2); |
717 | 731 | ||
718 | for (int col=col1; col<=col2; ++col) | 732 | for (int col=col1; col<=col2; ++col) |
719 | sheet->adjustColumn(col); | 733 | sheet->adjustColumn(col); |
720 | } | 734 | } |
721 | 735 | ||
722 | void MainWindow::slotColumnShow() | 736 | void MainWindow::slotColumnShow() |
723 | { | 737 | { |
724 | int row1, row2, col1, col2; | 738 | int row1, row2, col1, col2; |
725 | sheet->getSelection(&row1, &col1, &row2, &col2); | 739 | sheet->getSelection(&row1, &col1, &row2, &col2); |
726 | 740 | ||
727 | for (int col=col1; col<=col2; ++col) | 741 | for (int col=col1; col<=col2; ++col) |
728 | sheet->showColumn(col); | 742 | sheet->showColumn(col); |
729 | } | 743 | } |
730 | 744 | ||
731 | void MainWindow::slotColumnHide() | 745 | void MainWindow::slotColumnHide() |
732 | { | 746 | { |
733 | int row1, row2, col1, col2; | 747 | int row1, row2, col1, col2; |
734 | sheet->getSelection(&row1, &col1, &row2, &col2); | 748 | sheet->getSelection(&row1, &col1, &row2, &col2); |
735 | 749 | ||
736 | for (int col=col1; col<=col2; ++col) | 750 | for (int col=col1; col<=col2; ++col) |
737 | sheet->hideColumn(col); | 751 | sheet->hideColumn(col); |
738 | } | 752 | } |
739 | 753 | ||
740 | void MainWindow::slotFileSaveAs() | 754 | void MainWindow::slotFileSaveAs() |
741 | { | 755 | { |
742 | TextDialog dialogText(this); | 756 | TextDialog dialogText(this); |
743 | if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc.name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; | 757 | if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc.name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; |
744 | 758 | ||
745 | currentDoc.setName(dialogText.getValue()); | 759 | currentDoc.setName(dialogText.getValue()); |
746 | documentSave(currentDoc); | 760 | documentSave(currentDoc); |
747 | } | 761 | } |
748 | 762 | ||
749 | void MainWindow::slotSheetRename() | 763 | void MainWindow::slotSheetRename() |
750 | { | 764 | { |
751 | TextDialog dialogText(this); | 765 | TextDialog dialogText(this); |
752 | if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; | 766 | if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; |
753 | QString newName=dialogText.getValue(); | 767 | QString newName=dialogText.getValue(); |
754 | 768 | ||
755 | typeSheet *tempSheet=findSheet(newName); | 769 | typeSheet *tempSheet=findSheet(newName); |
756 | if (tempSheet) | 770 | if (tempSheet) |
757 | { | 771 | { |
758 | QMessageBox::critical(this, tr("Error"), tr("There is already a sheet named '"+newName+'\'')); | 772 | QMessageBox::critical(this, tr("Error"), tr("There is already a sheet named '"+newName+'\'')); |
759 | return; | 773 | return; |
760 | } | 774 | } |
761 | 775 | ||
762 | tempSheet=findSheet(sheet->getName()); | 776 | tempSheet=findSheet(sheet->getName()); |
763 | for (int i=0; i<comboSheets->count(); ++i) | 777 | for (int i=0; i<comboSheets->count(); ++i) |
764 | if (comboSheets->text(i)==tempSheet->name) | 778 | if (comboSheets->text(i)==tempSheet->name) |
765 | { | 779 | { |
766 | comboSheets->changeItem(newName, i); | 780 | comboSheets->changeItem(newName, i); |
767 | break; | 781 | break; |
768 | } | 782 | } |
769 | tempSheet->name=newName; | 783 | tempSheet->name=newName; |
770 | sheet->setName(newName); | 784 | sheet->setName(newName); |
771 | } | 785 | } |
772 | 786 | ||
773 | void MainWindow::slotSheetRemove() | 787 | void MainWindow::slotSheetRemove() |
774 | { | 788 | { |
775 | if (comboSheets->count()<2) | 789 | if (comboSheets->count()<2) |
776 | { | 790 | { |
777 | QMessageBox::warning(this, tr("Error"), tr("There is only one sheet!")); | 791 | QMessageBox::warning(this, tr("Error"), tr("There is only one sheet!")); |
778 | return; | 792 | return; |
779 | } | 793 | } |
780 | if (QMessageBox::information(this, tr("Remove Sheet"), tr("Are you sure?"), QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes) | 794 | if (QMessageBox::information(this, tr("Remove Sheet"), tr("Are you sure?"), QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes) |
781 | { | 795 | { |
782 | typeSheet *tempSheet=findSheet(sheet->getName()); | 796 | typeSheet *tempSheet=findSheet(sheet->getName()); |
783 | for (int i=0; i<comboSheets->count(); ++i) | 797 | for (int i=0; i<comboSheets->count(); ++i) |
784 | if (comboSheets->text(i)==tempSheet->name) | 798 | if (comboSheets->text(i)==tempSheet->name) |
785 | { | 799 | { |
786 | comboSheets->removeItem(i); | 800 | comboSheets->removeItem(i); |
787 | break; | 801 | break; |
788 | } | 802 | } |
789 | comboSheets->setCurrentItem(0); | 803 | comboSheets->setCurrentItem(0); |
790 | slotSheetChanged(comboSheets->currentText()); | 804 | slotSheetChanged(comboSheets->currentText()); |
791 | listSheets.remove(tempSheet); | 805 | listSheets.remove(tempSheet); |
792 | } | 806 | } |
793 | } | 807 | } |
794 | 808 | ||
795 | void MainWindow::slotDataSort() | 809 | void MainWindow::slotDataSort() |
796 | { | 810 | { |
797 | SortDialog dialogSort(this); | 811 | SortDialog dialogSort(this); |
798 | dialogSort.showMaximized(); | 812 | dialogSort.showMaximized(); |
799 | dialogSort.exec(sheet); | 813 | dialogSort.exec(sheet); |
800 | } | 814 | } |
801 | 815 | ||
802 | void MainWindow::slotDocModified() | 816 | void MainWindow::slotDocModified() |
803 | { | 817 | { |
804 | documentModified=TRUE; | 818 | documentModified=TRUE; |
805 | } | 819 | } |
806 | 820 | ||
807 | void MainWindow::slotInsertCells() | 821 | void MainWindow::slotInsertCells() |
808 | { | 822 | { |
809 | QDialog dialogInsert(this, 0, TRUE); | 823 | QDialog dialogInsert(this, 0, TRUE); |
810 | dialogInsert.resize(180, 130); | 824 | dialogInsert.resize(180, 130); |
811 | dialogInsert.setCaption(tr("Insert Cells")); | 825 | dialogInsert.setCaption(tr("Insert Cells")); |
812 | 826 | ||
813 | QVButtonGroup *group=new QVButtonGroup(tr("&Type"), &dialogInsert); | 827 | QVButtonGroup *group=new QVButtonGroup(tr("&Type"), &dialogInsert); |
814 | group->setGeometry(10, 10, 160, 110); | 828 | group->setGeometry(10, 10, 160, 110); |
815 | QRadioButton *radio=new QRadioButton(tr("Shift cells &down"), group); | 829 | QRadioButton *radio=new QRadioButton(tr("Shift cells &down"), group); |
816 | radio=new QRadioButton(tr("Shift cells &right"), group); | 830 | radio=new QRadioButton(tr("Shift cells &right"), group); |
817 | radio=new QRadioButton(tr("Entire ro&w"), group); | 831 | radio=new QRadioButton(tr("Entire ro&w"), group); |
818 | radio=new QRadioButton(tr("Entire &column"), group); | 832 | radio=new QRadioButton(tr("Entire &column"), group); |
819 | group->setButton(0); | 833 | group->setButton(0); |
820 | 834 | ||
821 | if (dialogInsert.exec()==QDialog::Accepted) | 835 | if (dialogInsert.exec()==QDialog::Accepted) |
822 | switch (group->id(group->selected())) | 836 | switch (group->id(group->selected())) |
823 | { | 837 | { |
824 | case 0: sheet->insertRows(1, FALSE); break; | 838 | case 0: sheet->insertRows(1, FALSE); break; |
825 | case 1: sheet->insertColumns(1, FALSE); break; | 839 | case 1: sheet->insertColumns(1, FALSE); break; |
826 | case 2: sheet->insertRows(1, TRUE); break; | 840 | case 2: sheet->insertRows(1, TRUE); break; |
827 | case 3: sheet->insertColumns(1, TRUE); break; | 841 | case 3: sheet->insertColumns(1, TRUE); break; |
828 | } | 842 | } |
829 | } | 843 | } |
830 | 844 | ||
831 | void MainWindow::slotDataFindReplace() | 845 | void MainWindow::slotDataFindReplace() |
832 | { | 846 | { |
833 | FindDialog dialogFind(this); | 847 | FindDialog dialogFind(this); |
834 | dialogFind.showMaximized(); | 848 | dialogFind.showMaximized(); |
835 | dialogFind.exec(sheet); | 849 | dialogFind.exec(sheet); |
836 | } | 850 | } |
diff --git a/noncore/apps/opie-sheet/mainwindow.h b/noncore/apps/opie-sheet/mainwindow.h index ac90504..554e6f6 100644 --- a/noncore/apps/opie-sheet/mainwindow.h +++ b/noncore/apps/opie-sheet/mainwindow.h | |||
@@ -1,120 +1,134 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #ifndef MAINWINDOW_H | 15 | #ifndef MAINWINDOW_H |
2 | #define MAINWINDOW_H | 16 | #define MAINWINDOW_H |
3 | 17 | ||
4 | #include <qpe/applnk.h> | 18 | #include <qpe/applnk.h> |
5 | #include <qpe/fileselector.h> | 19 | #include <qpe/fileselector.h> |
6 | #include <qpe/qpemenubar.h> | 20 | #include <qpe/qpemenubar.h> |
7 | #include <qpe/qpetoolbar.h> | 21 | #include <qpe/qpetoolbar.h> |
8 | #include <qmainwindow.h> | 22 | #include <qmainwindow.h> |
9 | #include <qaction.h> | 23 | #include <qaction.h> |
10 | #include <qlineedit.h> | 24 | #include <qlineedit.h> |
11 | #include <qbutton.h> | 25 | #include <qbutton.h> |
12 | #include <qcombobox.h> | 26 | #include <qcombobox.h> |
13 | #include <qtoolbutton.h> | 27 | #include <qtoolbutton.h> |
14 | 28 | ||
15 | #include "sheet.h" | 29 | #include "sheet.h" |
16 | 30 | ||
17 | typedef struct typeSheet | 31 | typedef struct typeSheet |
18 | { | 32 | { |
19 | QString name; | 33 | QString name; |
20 | QList<typeCellData> data; | 34 | QList<typeCellData> data; |
21 | }; | 35 | }; |
22 | 36 | ||
23 | class MainWindow: public QMainWindow | 37 | class MainWindow: public QMainWindow |
24 | { | 38 | { |
25 | Q_OBJECT | 39 | Q_OBJECT |
26 | 40 | ||
27 | // QPE objects | 41 | // QPE objects |
28 | DocLnk currentDoc; | 42 | DocLnk currentDoc; |
29 | QPEMenuBar *menu; | 43 | QPEMenuBar *menu; |
30 | QPEToolBar *toolbarFunctions, *toolbarEdit, *toolbarStandard; | 44 | QPEToolBar *toolbarFunctions, *toolbarEdit, *toolbarStandard; |
31 | FileSelector *fileSelector; | 45 | FileSelector *fileSelector; |
32 | 46 | ||
33 | // QT objects | 47 | // QT objects |
34 | QPopupMenu *menuFile, *menuEdit, *menuInsert, *menuFormat, *menuData, *menuHelp, | 48 | QPopupMenu *menuFile, *menuEdit, *menuInsert, *menuFormat, *menuData, *menuHelp, |
35 | *submenuFunc, *submenuFuncStd, *submenuFuncMath, *submenuFuncStat, | 49 | *submenuFunc, *submenuFuncStd, *submenuFuncMath, *submenuFuncStat, |
36 | *submenuRow, *submenuCol, *submenuSheet; | 50 | *submenuRow, *submenuCol, *submenuSheet; |
37 | QAction *fileNew, *fileOpen, *fileSave, *fileSaveAs, *fileQuit, *helpAbout, *editAccept, *editCancel, *formatCells, | 51 | QAction *fileNew, *fileOpen, *fileSave, *fileSaveAs, *fileQuit, *helpAbout, *editAccept, *editCancel, *formatCells, |
38 | *funcPlus, *funcMinus, *funcCross, *funcDivide, *funcParanOpen, *funcParanClose, *funcComma, *funcEqual, | 52 | *funcPlus, *funcMinus, *funcCross, *funcDivide, *funcParanOpen, *funcParanClose, *funcComma, *funcEqual, |
39 | *editCut, *editCopy, *editPaste, *editPasteContents, *editClear, *insertCols, *insertRows, *insertSheets, *insertCells, | 53 | *editCut, *editCopy, *editPaste, *editPasteContents, *editClear, *insertCols, *insertRows, *insertSheets, *insertCells, |
40 | *rowHeight, *rowShow, *rowHide, *rowAdjust, *colWidth, *colShow, *colHide, *colAdjust, *sheetRename, *sheetRemove, | 54 | *rowHeight, *rowShow, *rowHide, *rowAdjust, *colWidth, *colShow, *colHide, *colAdjust, *sheetRename, *sheetRemove, |
41 | *dataSort, *dataFindReplace, *editCellSelect, *helpGeneral; | 55 | *dataSort, *dataFindReplace, *editCellSelect, *helpGeneral; |
42 | QLineEdit *editData; | 56 | QLineEdit *editData; |
43 | QButton *buttonUp, *buttonDown, *buttonLeft, *buttonRight; | 57 | QButton *buttonUp, *buttonDown, *buttonLeft, *buttonRight; |
44 | QComboBox *comboSheets; | 58 | QComboBox *comboSheets; |
45 | QToolButton *toolFunction; | 59 | QToolButton *toolFunction; |
46 | QList<typeSheet> listSheets; | 60 | QList<typeSheet> listSheets; |
47 | QString helpFile; | 61 | QString helpFile; |
48 | 62 | ||
49 | // Other objects | 63 | // Other objects |
50 | Sheet *sheet; | 64 | Sheet *sheet; |
51 | 65 | ||
52 | // Variables | 66 | // Variables |
53 | bool documentModified; | 67 | bool documentModified; |
54 | 68 | ||
55 | // Private functions | 69 | // Private functions |
56 | void initMenu(); | 70 | void initMenu(); |
57 | void initActions(); | 71 | void initActions(); |
58 | void initFunctionsToolbar(); | 72 | void initFunctionsToolbar(); |
59 | void initEditToolbar(); | 73 | void initEditToolbar(); |
60 | void initStandardToolbar(); | 74 | void initStandardToolbar(); |
61 | void initSheet(); | 75 | void initSheet(); |
62 | void addToData(const QString &data); | 76 | void addToData(const QString &data); |
63 | int saveCurrentFile(bool ask=TRUE); | 77 | int saveCurrentFile(bool ask=TRUE); |
64 | void documentOpen(const DocLnk &lnkDoc); | 78 | void documentOpen(const DocLnk &lnkDoc); |
65 | void copyDocLnk(const DocLnk &source, DocLnk &target); | 79 | void copyDocLnk(const DocLnk &source, DocLnk &target); |
66 | void documentSave(DocLnk &lnkDoc); | 80 | void documentSave(DocLnk &lnkDoc); |
67 | void closeEvent(QCloseEvent *e); | 81 | void closeEvent(QCloseEvent *e); |
68 | void addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w); | 82 | void addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w); |
69 | typeSheet *createNewSheet(); | 83 | typeSheet *createNewSheet(); |
70 | typeSheet *findSheet(const QString &name); | 84 | typeSheet *findSheet(const QString &name); |
71 | 85 | ||
72 | private slots: | 86 | private slots: |
73 | void slotFileNew(); | 87 | void slotFileNew(); |
74 | void slotFileOpen(); | 88 | void slotFileOpen(); |
75 | void slotFileSave(); | 89 | void slotFileSave(); |
76 | void slotFileSaveAs(); | 90 | void slotFileSaveAs(); |
77 | void slotHelpAbout(); | 91 | void slotHelpAbout(); |
78 | void slotHelpGeneral(); | 92 | void slotHelpGeneral(); |
79 | void slotEditAccept(); | 93 | void slotEditAccept(); |
80 | void slotEditCancel(); | 94 | void slotEditCancel(); |
81 | void slotEditPaste(); | 95 | void slotEditPaste(); |
82 | void slotEditPasteContents(); | 96 | void slotEditPasteContents(); |
83 | void slotFormatCells(); | 97 | void slotFormatCells(); |
84 | void slotInsertCells(); | 98 | void slotInsertCells(); |
85 | void slotInsertRows(); | 99 | void slotInsertRows(); |
86 | void slotInsertCols(); | 100 | void slotInsertCols(); |
87 | void slotInsertSheets(); | 101 | void slotInsertSheets(); |
88 | void slotDataSort(); | 102 | void slotDataSort(); |
89 | void slotDataFindReplace(); | 103 | void slotDataFindReplace(); |
90 | void slotRowHeight(); | 104 | void slotRowHeight(); |
91 | void slotRowAdjust(); | 105 | void slotRowAdjust(); |
92 | void slotRowShow(); | 106 | void slotRowShow(); |
93 | void slotRowHide(); | 107 | void slotRowHide(); |
94 | void slotColumnWidth(); | 108 | void slotColumnWidth(); |
95 | void slotColumnAdjust(); | 109 | void slotColumnAdjust(); |
96 | void slotColumnShow(); | 110 | void slotColumnShow(); |
97 | void slotColumnHide(); | 111 | void slotColumnHide(); |
98 | void slotSheetRename(); | 112 | void slotSheetRename(); |
99 | void slotSheetRemove(); | 113 | void slotSheetRemove(); |
100 | void slotFuncOutput(); | 114 | void slotFuncOutput(); |
101 | void slotCellSelect(bool lock); | 115 | void slotCellSelect(bool lock); |
102 | void slotCellClicked(const QString &cell); | 116 | void slotCellClicked(const QString &cell); |
103 | void slotSheetChanged(const QString &name); | 117 | void slotSheetChanged(const QString &name); |
104 | void slotDocModified(); | 118 | void slotDocModified(); |
105 | void selectorShow(); | 119 | void selectorShow(); |
106 | void selectorHide(); | 120 | void selectorHide(); |
107 | void selectorFileNew(const DocLnk &lnkDoc); | 121 | void selectorFileNew(const DocLnk &lnkDoc); |
108 | void selectorFileOpen(const DocLnk &lnkDoc); | 122 | void selectorFileOpen(const DocLnk &lnkDoc); |
109 | 123 | ||
110 | public: | 124 | public: |
111 | MainWindow(); | 125 | MainWindow(); |
112 | ~MainWindow(); | 126 | ~MainWindow(); |
113 | 127 | ||
114 | void setHelpFile(const QString &help_filename) { helpFile=help_filename; } | 128 | void setHelpFile(const QString &help_filename) { helpFile=help_filename; } |
115 | 129 | ||
116 | public slots: | 130 | public slots: |
117 | void setDocument(const QString &applnk_filename); | 131 | void setDocument(const QString &applnk_filename); |
118 | }; | 132 | }; |
119 | 133 | ||
120 | #endif | 134 | #endif |
diff --git a/noncore/apps/opie-sheet/numberdlg.cpp b/noncore/apps/opie-sheet/numberdlg.cpp index de84378..e8de639 100644 --- a/noncore/apps/opie-sheet/numberdlg.cpp +++ b/noncore/apps/opie-sheet/numberdlg.cpp | |||
@@ -1,35 +1,49 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #include "numberdlg.h" | 15 | #include "numberdlg.h" |
2 | 16 | ||
3 | NumberDialog::NumberDialog(QWidget *parent=0) | 17 | NumberDialog::NumberDialog(QWidget *parent=0) |
4 | :QDialog(parent, 0, TRUE) | 18 | :QDialog(parent, 0, TRUE) |
5 | { | 19 | { |
6 | edit=new QSpinBox(this); | 20 | edit=new QSpinBox(this); |
7 | edit->setGeometry(120, 10, 70, 25); | 21 | edit->setGeometry(120, 10, 70, 25); |
8 | 22 | ||
9 | label=new QLabel(this); | 23 | label=new QLabel(this); |
10 | label->setGeometry(10, 10, 100, 25); | 24 | label->setGeometry(10, 10, 100, 25); |
11 | label->setBuddy(edit); | 25 | label->setBuddy(edit); |
12 | 26 | ||
13 | resize(200, 45); | 27 | resize(200, 45); |
14 | } | 28 | } |
15 | 29 | ||
16 | NumberDialog::~NumberDialog() | 30 | NumberDialog::~NumberDialog() |
17 | { | 31 | { |
18 | } | 32 | } |
19 | 33 | ||
20 | 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, int value=1, int min=1, int max=99, int step=1) |
21 | { | 35 | { |
22 | setCaption(caption); | 36 | setCaption(caption); |
23 | label->setText(text); | 37 | label->setText(text); |
24 | edit->setValue(value); | 38 | edit->setValue(value); |
25 | edit->setMinValue(min); | 39 | edit->setMinValue(min); |
26 | edit->setMaxValue(max); | 40 | edit->setMaxValue(max); |
27 | edit->setLineStep(step); | 41 | edit->setLineStep(step); |
28 | 42 | ||
29 | return QDialog::exec(); | 43 | return QDialog::exec(); |
30 | } | 44 | } |
31 | 45 | ||
32 | int NumberDialog::getValue() | 46 | int NumberDialog::getValue() |
33 | { | 47 | { |
34 | return edit->value(); | 48 | return edit->value(); |
35 | } | 49 | } |
diff --git a/noncore/apps/opie-sheet/numberdlg.h b/noncore/apps/opie-sheet/numberdlg.h index 46af1d0..81e3326 100644 --- a/noncore/apps/opie-sheet/numberdlg.h +++ b/noncore/apps/opie-sheet/numberdlg.h | |||
@@ -1,24 +1,38 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #ifndef NUMBERDLG_H | 15 | #ifndef NUMBERDLG_H |
2 | #define NUMBERDLG_H | 16 | #define NUMBERDLG_H |
3 | 17 | ||
4 | #include <qdialog.h> | 18 | #include <qdialog.h> |
5 | #include <qlabel.h> | 19 | #include <qlabel.h> |
6 | #include <qspinbox.h> | 20 | #include <qspinbox.h> |
7 | 21 | ||
8 | class NumberDialog: public QDialog | 22 | class NumberDialog: public QDialog |
9 | { | 23 | { |
10 | Q_OBJECT | 24 | Q_OBJECT |
11 | 25 | ||
12 | // QT objects | 26 | // QT objects |
13 | QLabel *label; | 27 | QLabel *label; |
14 | QSpinBox *edit; | 28 | QSpinBox *edit; |
15 | 29 | ||
16 | public: | 30 | public: |
17 | NumberDialog(QWidget *parent=0); | 31 | NumberDialog(QWidget *parent=0); |
18 | ~NumberDialog(); | 32 | ~NumberDialog(); |
19 | 33 | ||
20 | int exec(const QString &caption, const QString &text, int value=1, int min=1, int max=99, int step=1); | 34 | int exec(const QString &caption, const QString &text, int value=1, int min=1, int max=99, int step=1); |
21 | int getValue(); | 35 | int getValue(); |
22 | }; | 36 | }; |
23 | 37 | ||
24 | #endif | 38 | #endif |
diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp index 9526937..1d7ec6f 100644 --- a/noncore/apps/opie-sheet/sheet.cpp +++ b/noncore/apps/opie-sheet/sheet.cpp | |||
@@ -1,849 +1,863 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #include "sheet.h" | 15 | #include "sheet.h" |
2 | 16 | ||
3 | #include <qmainwindow.h> | 17 | #include <qmainwindow.h> |
4 | #include <qmessagebox.h> | 18 | #include <qmessagebox.h> |
5 | #include <math.h> | 19 | #include <math.h> |
6 | 20 | ||
7 | #define DEFAULT_COL_WIDTH 50 | 21 | #define DEFAULT_COL_WIDTH 50 |
8 | 22 | ||
9 | Sheet::Sheet(int numRows, int numCols, QWidget *parent) | 23 | Sheet::Sheet(int numRows, int numCols, QWidget *parent) |
10 | :QTable(numRows, numCols, parent) | 24 | :QTable(numRows, numCols, parent) |
11 | { | 25 | { |
12 | defaultBorders.right=defaultBorders.bottom=QPen(Qt::gray, 1, Qt::SolidLine); | 26 | defaultBorders.right=defaultBorders.bottom=QPen(Qt::gray, 1, Qt::SolidLine); |
13 | defaultCellData.data=""; | 27 | defaultCellData.data=""; |
14 | defaultCellData.background=QBrush(Qt::white, Qt::SolidPattern); | 28 | defaultCellData.background=QBrush(Qt::white, Qt::SolidPattern); |
15 | defaultCellData.alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop); | 29 | defaultCellData.alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop); |
16 | defaultCellData.fontColor=Qt::black; | 30 | defaultCellData.fontColor=Qt::black; |
17 | defaultCellData.font=font(); | 31 | defaultCellData.font=font(); |
18 | defaultCellData.borders=defaultBorders; | 32 | defaultCellData.borders=defaultBorders; |
19 | 33 | ||
20 | selectionNo=-1; | 34 | selectionNo=-1; |
21 | setSelectionMode(QTable::Single); | 35 | setSelectionMode(QTable::Single); |
22 | 36 | ||
23 | sheetData.setAutoDelete(TRUE); | 37 | sheetData.setAutoDelete(TRUE); |
24 | clipboardData.setAutoDelete(TRUE); | 38 | clipboardData.setAutoDelete(TRUE); |
25 | for (int i=0; i<numCols; ++i) | 39 | for (int i=0; i<numCols; ++i) |
26 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); | 40 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); |
27 | 41 | ||
28 | connect(this, SIGNAL(currentChanged(int, int)), this, SLOT(slotCellSelected(int, int))); | 42 | connect(this, SIGNAL(currentChanged(int, int)), this, SLOT(slotCellSelected(int, int))); |
29 | connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(slotCellChanged(int, int))); | 43 | connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(slotCellChanged(int, int))); |
30 | } | 44 | } |
31 | 45 | ||
32 | Sheet::~Sheet() | 46 | Sheet::~Sheet() |
33 | { | 47 | { |
34 | } | 48 | } |
35 | 49 | ||
36 | typeCellData *Sheet::findCellData(int row, int col) | 50 | typeCellData *Sheet::findCellData(int row, int col) |
37 | { | 51 | { |
38 | typeCellData *tempCellData; | 52 | typeCellData *tempCellData; |
39 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 53 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
40 | if (tempCellData->row==row && tempCellData->col==col) | 54 | if (tempCellData->row==row && tempCellData->col==col) |
41 | return tempCellData; | 55 | return tempCellData; |
42 | return NULL; | 56 | return NULL; |
43 | } | 57 | } |
44 | 58 | ||
45 | void Sheet::slotCellSelected(int row, int col) | 59 | void Sheet::slotCellSelected(int row, int col) |
46 | { | 60 | { |
47 | typeCellData *cellData=findCellData(row, col); | 61 | typeCellData *cellData=findCellData(row, col); |
48 | if (cellData) | 62 | if (cellData) |
49 | emit currentDataChanged(cellData->data); | 63 | emit currentDataChanged(cellData->data); |
50 | else | 64 | else |
51 | emit currentDataChanged(""); | 65 | emit currentDataChanged(""); |
52 | } | 66 | } |
53 | 67 | ||
54 | typeCellData *Sheet::createCellData(int row, int col) | 68 | typeCellData *Sheet::createCellData(int row, int col) |
55 | { | 69 | { |
56 | if (row<0 || col<0) return NULL; | 70 | if (row<0 || col<0) return NULL; |
57 | typeCellData *cellData=new typeCellData; | 71 | typeCellData *cellData=new typeCellData; |
58 | cellData->row=row; | 72 | cellData->row=row; |
59 | cellData->col=col; | 73 | cellData->col=col; |
60 | cellData->data=defaultCellData.data; | 74 | cellData->data=defaultCellData.data; |
61 | cellData->borders=defaultCellData.borders; | 75 | cellData->borders=defaultCellData.borders; |
62 | cellData->alignment=defaultCellData.alignment; | 76 | cellData->alignment=defaultCellData.alignment; |
63 | cellData->font=defaultCellData.font; | 77 | cellData->font=defaultCellData.font; |
64 | cellData->fontColor=defaultCellData.fontColor; | 78 | cellData->fontColor=defaultCellData.fontColor; |
65 | cellData->background=defaultCellData.background; | 79 | cellData->background=defaultCellData.background; |
66 | sheetData.append(cellData); | 80 | sheetData.append(cellData); |
67 | return cellData; | 81 | return cellData; |
68 | } | 82 | } |
69 | 83 | ||
70 | void Sheet::slotCellChanged(int row, int col) | 84 | void Sheet::slotCellChanged(int row, int col) |
71 | { | 85 | { |
72 | typeCellData *cellData=findCellData(row, col); | 86 | typeCellData *cellData=findCellData(row, col); |
73 | if (!cellData) cellData=createCellData(row, col); | 87 | if (!cellData) cellData=createCellData(row, col); |
74 | if (cellData) cellData->data=text(row, col); | 88 | if (cellData) cellData->data=text(row, col); |
75 | for (cellData=sheetData.first(); cellData; cellData=sheetData.next()) | 89 | for (cellData=sheetData.first(); cellData; cellData=sheetData.next()) |
76 | setText(cellData->row, cellData->col, dataParser(cellData->data)); | 90 | setText(cellData->row, cellData->col, dataParser(cellData->data)); |
77 | emit sheetModified(); | 91 | emit sheetModified(); |
78 | } | 92 | } |
79 | 93 | ||
80 | void Sheet::swapCells(int row1, int col1, int row2, int col2) | 94 | void Sheet::swapCells(int row1, int col1, int row2, int col2) |
81 | { | 95 | { |
82 | typeCellData *cellData1=findCellData(row1, col1), *cellData2=findCellData(row2, col2); | 96 | typeCellData *cellData1=findCellData(row1, col1), *cellData2=findCellData(row2, col2); |
83 | if (!cellData1) cellData1=createCellData(row1, col1); | 97 | if (!cellData1) cellData1=createCellData(row1, col1); |
84 | if (!cellData2) cellData2=createCellData(row2, col2); | 98 | if (!cellData2) cellData2=createCellData(row2, col2); |
85 | if (cellData1 && cellData2) | 99 | if (cellData1 && cellData2) |
86 | { | 100 | { |
87 | QString tempData(cellData1->data); | 101 | QString tempData(cellData1->data); |
88 | cellData1->data=cellData2->data; | 102 | cellData1->data=cellData2->data; |
89 | cellData2->data=tempData; | 103 | cellData2->data=tempData; |
90 | setText(cellData1->row, cellData1->col, dataParser(cellData1->data)); | 104 | setText(cellData1->row, cellData1->col, dataParser(cellData1->data)); |
91 | setText(cellData2->row, cellData2->col, dataParser(cellData2->data)); | 105 | setText(cellData2->row, cellData2->col, dataParser(cellData2->data)); |
92 | emit sheetModified(); | 106 | emit sheetModified(); |
93 | } | 107 | } |
94 | } | 108 | } |
95 | 109 | ||
96 | 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=FALSE, const QString funcName="") |
97 | { | 111 | { |
98 | QString params(parameters); | 112 | QString params(parameters); |
99 | int position; | 113 | int position; |
100 | for (int i=0; i<paramNo; ++i) | 114 | for (int i=0; i<paramNo; ++i) |
101 | { | 115 | { |
102 | position=params.find(','); | 116 | position=params.find(','); |
103 | if (position<0) | 117 | if (position<0) |
104 | { | 118 | { |
105 | 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+'\'')); |
106 | return QString(); | 120 | return QString(); |
107 | } | 121 | } |
108 | params=params.mid(position+1); | 122 | params=params.mid(position+1); |
109 | } | 123 | } |
110 | position=params.find(','); | 124 | position=params.find(','); |
111 | if (position<0) return params; | 125 | if (position<0) return params; |
112 | return params.left(position); | 126 | return params.left(position); |
113 | } | 127 | } |
114 | 128 | ||
115 | 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) |
116 | { | 130 | { |
117 | int row, col; | 131 | int row, col; |
118 | 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; |
119 | if (*row1>*row2) | 133 | if (*row1>*row2) |
120 | { | 134 | { |
121 | row=*row1; | 135 | row=*row1; |
122 | *row1=*row2; | 136 | *row1=*row2; |
123 | *row2=row; | 137 | *row2=row; |
124 | } | 138 | } |
125 | if (*col1>*col2) | 139 | if (*col1>*col2) |
126 | { | 140 | { |
127 | col=*col1; | 141 | col=*col1; |
128 | *col1=*col2; | 142 | *col1=*col2; |
129 | *col2=col; | 143 | *col2=col; |
130 | } | 144 | } |
131 | return TRUE; | 145 | return TRUE; |
132 | } | 146 | } |
133 | 147 | ||
134 | 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=FALSE) |
135 | { | 149 | { |
136 | int position=variable.find(QRegExp("\\d")); | 150 | int position=variable.find(QRegExp("\\d")); |
137 | if (position<1) | 151 | if (position<1) |
138 | { | 152 | { |
139 | if (giveError) QMessageBox::critical(this, tr("Error"), tr("Invalid variable: '"+variable+'\'')); | 153 | if (giveError) QMessageBox::critical(this, tr("Error"), tr("Invalid variable: '"+variable+'\'')); |
140 | return FALSE; | 154 | return FALSE; |
141 | } | 155 | } |
142 | *row=variable.mid(position).toInt()-1; | 156 | *row=variable.mid(position).toInt()-1; |
143 | *col=getHeaderColumn(variable.left(position))-1; | 157 | *col=getHeaderColumn(variable.left(position))-1; |
144 | return TRUE; | 158 | return TRUE; |
145 | } | 159 | } |
146 | 160 | ||
147 | double Sheet::calculateVariable(const QString &variable) | 161 | double Sheet::calculateVariable(const QString &variable) |
148 | { | 162 | { |
149 | bool ok; | 163 | bool ok; |
150 | double tempResult=variable.toDouble(&ok); | 164 | double tempResult=variable.toDouble(&ok); |
151 | if (ok) return tempResult; | 165 | if (ok) return tempResult; |
152 | 166 | ||
153 | int row, col; | 167 | int row, col; |
154 | return (findRowColumn(variable, &row, &col, TRUE) ? text(row, col).toDouble() : 0); | 168 | return (findRowColumn(variable, &row, &col, TRUE) ? text(row, col).toDouble() : 0); |
155 | } | 169 | } |
156 | 170 | ||
157 | double Sheet::functionSum(const QString ¶m1, const QString ¶m2) | 171 | double Sheet::functionSum(const QString ¶m1, const QString ¶m2) |
158 | { | 172 | { |
159 | int row1, col1, row2, col2, row, col; | 173 | int row1, col1, row2, col2, row, col; |
160 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 174 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
161 | 175 | ||
162 | double result=0, tempResult; | 176 | double result=0, tempResult; |
163 | bool ok; | 177 | bool ok; |
164 | for (row=row1; row<=row2; ++row) | 178 | for (row=row1; row<=row2; ++row) |
165 | for (col=col1; col<=col2; ++col) | 179 | for (col=col1; col<=col2; ++col) |
166 | { | 180 | { |
167 | tempResult=text(row, col).toDouble(&ok); | 181 | tempResult=text(row, col).toDouble(&ok); |
168 | if (ok) result+=tempResult; | 182 | if (ok) result+=tempResult; |
169 | } | 183 | } |
170 | 184 | ||
171 | return result; | 185 | return result; |
172 | } | 186 | } |
173 | 187 | ||
174 | double Sheet::functionMin(const QString ¶m1, const QString ¶m2) | 188 | double Sheet::functionMin(const QString ¶m1, const QString ¶m2) |
175 | { | 189 | { |
176 | int row1, col1, row2, col2, row, col; | 190 | int row1, col1, row2, col2, row, col; |
177 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 191 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
178 | 192 | ||
179 | double min=0, tempMin; | 193 | double min=0, tempMin; |
180 | bool ok, init=FALSE; | 194 | bool ok, init=FALSE; |
181 | for (row=row1; row<=row2; ++row) | 195 | for (row=row1; row<=row2; ++row) |
182 | for (col=col1; col<=col2; ++col) | 196 | for (col=col1; col<=col2; ++col) |
183 | { | 197 | { |
184 | tempMin=text(row, col).toDouble(&ok); | 198 | tempMin=text(row, col).toDouble(&ok); |
185 | if (ok && (!init || tempMin<min)) | 199 | if (ok && (!init || tempMin<min)) |
186 | { | 200 | { |
187 | min=tempMin; | 201 | min=tempMin; |
188 | init=TRUE; | 202 | init=TRUE; |
189 | } | 203 | } |
190 | } | 204 | } |
191 | 205 | ||
192 | return min; | 206 | return min; |
193 | } | 207 | } |
194 | 208 | ||
195 | double Sheet::functionMax(const QString ¶m1, const QString ¶m2) | 209 | double Sheet::functionMax(const QString ¶m1, const QString ¶m2) |
196 | { | 210 | { |
197 | int row1, col1, row2, col2, row, col; | 211 | int row1, col1, row2, col2, row, col; |
198 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 212 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
199 | 213 | ||
200 | double max=0, tempMax; | 214 | double max=0, tempMax; |
201 | bool ok, init=FALSE; | 215 | bool ok, init=FALSE; |
202 | for (row=row1; row<=row2; ++row) | 216 | for (row=row1; row<=row2; ++row) |
203 | for (col=col1; col<=col2; ++col) | 217 | for (col=col1; col<=col2; ++col) |
204 | { | 218 | { |
205 | tempMax=text(row, col).toDouble(&ok); | 219 | tempMax=text(row, col).toDouble(&ok); |
206 | if (ok && (!init || tempMax>max)) | 220 | if (ok && (!init || tempMax>max)) |
207 | { | 221 | { |
208 | max=tempMax; | 222 | max=tempMax; |
209 | init=TRUE; | 223 | init=TRUE; |
210 | } | 224 | } |
211 | } | 225 | } |
212 | 226 | ||
213 | return max; | 227 | return max; |
214 | } | 228 | } |
215 | 229 | ||
216 | double Sheet::functionAvg(const QString ¶m1, const QString ¶m2) | 230 | double Sheet::functionAvg(const QString ¶m1, const QString ¶m2) |
217 | { | 231 | { |
218 | double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2); | 232 | double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2); |
219 | return (resultCount>0 ? resultSum/resultCount : 0); | 233 | return (resultCount>0 ? resultSum/resultCount : 0); |
220 | } | 234 | } |
221 | 235 | ||
222 | double Sheet::functionCount(const QString ¶m1, const QString ¶m2) | 236 | double Sheet::functionCount(const QString ¶m1, const QString ¶m2) |
223 | { | 237 | { |
224 | int row1, col1, row2, col2, row, col; | 238 | int row1, col1, row2, col2, row, col; |
225 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 239 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
226 | 240 | ||
227 | int divider=0; | 241 | int divider=0; |
228 | bool ok; | 242 | bool ok; |
229 | for (row=row1; row<=row2; ++row) | 243 | for (row=row1; row<=row2; ++row) |
230 | for (col=col1; col<=col2; ++col) | 244 | for (col=col1; col<=col2; ++col) |
231 | { | 245 | { |
232 | text(row, col).toDouble(&ok); | 246 | text(row, col).toDouble(&ok); |
233 | if (ok) ++divider; | 247 | if (ok) ++divider; |
234 | } | 248 | } |
235 | 249 | ||
236 | return divider; | 250 | return divider; |
237 | } | 251 | } |
238 | 252 | ||
239 | double Sheet::calculateFunction(const QString &function, const QString ¶meters) | 253 | double Sheet::calculateFunction(const QString &function, const QString ¶meters) |
240 | { | 254 | { |
241 | if (function=="+") | 255 | if (function=="+") |
242 | return calculateVariable(getParameter(parameters, 0))+calculateVariable(getParameter(parameters, 1)); | 256 | return calculateVariable(getParameter(parameters, 0))+calculateVariable(getParameter(parameters, 1)); |
243 | if (function=="-") | 257 | if (function=="-") |
244 | return calculateVariable(getParameter(parameters, 0))-calculateVariable(getParameter(parameters, 1)); | 258 | return calculateVariable(getParameter(parameters, 0))-calculateVariable(getParameter(parameters, 1)); |
245 | if (function=="*") | 259 | if (function=="*") |
246 | return calculateVariable(getParameter(parameters, 0))*calculateVariable(getParameter(parameters, 1)); | 260 | return calculateVariable(getParameter(parameters, 0))*calculateVariable(getParameter(parameters, 1)); |
247 | if (function=="/") | 261 | if (function=="/") |
248 | return calculateVariable(getParameter(parameters, 0))/calculateVariable(getParameter(parameters, 1)); | 262 | return calculateVariable(getParameter(parameters, 0))/calculateVariable(getParameter(parameters, 1)); |
249 | if (function=="SUM") | 263 | if (function=="SUM") |
250 | 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)); |
251 | if (function=="COUNT") | 265 | if (function=="COUNT") |
252 | 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)); |
253 | if (function=="MIN") | 267 | if (function=="MIN") |
254 | 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)); |
255 | if (function=="MAX") | 269 | if (function=="MAX") |
256 | 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)); |
257 | if (function=="AVG") | 271 | if (function=="AVG") |
258 | 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)); |
259 | if (function=="ABS") | 273 | if (function=="ABS") |
260 | return fabs(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 274 | return fabs(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
261 | if (function=="SIN") | 275 | if (function=="SIN") |
262 | return sin(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 276 | return sin(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
263 | if (function=="COS") | 277 | if (function=="COS") |
264 | return cos(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 278 | return cos(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
265 | if (function=="TAN") | 279 | if (function=="TAN") |
266 | return tan(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 280 | return tan(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
267 | if (function=="ATAN") | 281 | if (function=="ATAN") |
268 | return atan(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 282 | return atan(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
269 | if (function=="ATAN2") | 283 | if (function=="ATAN2") |
270 | return atan2(calculateVariable(getParameter(parameters, 0, TRUE, function)), calculateVariable(getParameter(parameters, 1, TRUE, function))); | 284 | return atan2(calculateVariable(getParameter(parameters, 0, TRUE, function)), calculateVariable(getParameter(parameters, 1, TRUE, function))); |
271 | if (function=="ASIN") | 285 | if (function=="ASIN") |
272 | return asin(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 286 | return asin(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
273 | if (function=="ACOS") | 287 | if (function=="ACOS") |
274 | return acos(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 288 | return acos(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
275 | if (function=="EXP") | 289 | if (function=="EXP") |
276 | return exp(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 290 | return exp(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
277 | if (function=="LOG") | 291 | if (function=="LOG") |
278 | return log(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 292 | return log(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
279 | if (function=="POW") | 293 | if (function=="POW") |
280 | return pow(calculateVariable(getParameter(parameters, 0, TRUE, function)), calculateVariable(getParameter(parameters, 1, TRUE, function))); | 294 | return pow(calculateVariable(getParameter(parameters, 0, TRUE, function)), calculateVariable(getParameter(parameters, 1, TRUE, function))); |
281 | return 0; | 295 | return 0; |
282 | } | 296 | } |
283 | 297 | ||
284 | int Sheet::getOperatorPriority(char oper) | 298 | int Sheet::getOperatorPriority(char oper) |
285 | { | 299 | { |
286 | switch (oper) | 300 | switch (oper) |
287 | { | 301 | { |
288 | case '+': | 302 | case '+': |
289 | case '-': | 303 | case '-': |
290 | return 1; | 304 | return 1; |
291 | 305 | ||
292 | case '*': | 306 | case '*': |
293 | case '/': | 307 | case '/': |
294 | return 2; | 308 | return 2; |
295 | } | 309 | } |
296 | return 0; | 310 | return 0; |
297 | } | 311 | } |
298 | 312 | ||
299 | void Sheet::pushCharStack(QStack<QChar> *stackChars, const QChar &character) | 313 | void Sheet::pushCharStack(QStack<QChar> *stackChars, const QChar &character) |
300 | { | 314 | { |
301 | QChar *temp=new QChar(character); | 315 | QChar *temp=new QChar(character); |
302 | stackChars->push(temp); | 316 | stackChars->push(temp); |
303 | } | 317 | } |
304 | 318 | ||
305 | void Sheet::pushStringStack(QStack<QString> *stackStrings, const QString &string) | 319 | void Sheet::pushStringStack(QStack<QString> *stackStrings, const QString &string) |
306 | { | 320 | { |
307 | QString *temp=new QString(string); | 321 | QString *temp=new QString(string); |
308 | stackStrings->push(temp); | 322 | stackStrings->push(temp); |
309 | } | 323 | } |
310 | 324 | ||
311 | QChar Sheet::popCharStack(QStack<QChar> *stackChars) | 325 | QChar Sheet::popCharStack(QStack<QChar> *stackChars) |
312 | { | 326 | { |
313 | if (stackChars->isEmpty()) | 327 | if (stackChars->isEmpty()) |
314 | { | 328 | { |
315 | QMessageBox::critical(this, tr("Error"), tr("Syntax error!")); | 329 | QMessageBox::critical(this, tr("Error"), tr("Syntax error!")); |
316 | return '0'; | 330 | return '0'; |
317 | } | 331 | } |
318 | 332 | ||
319 | QChar *temp=stackChars->pop(); | 333 | QChar *temp=stackChars->pop(); |
320 | QChar temp2(*temp); | 334 | QChar temp2(*temp); |
321 | delete temp; | 335 | delete temp; |
322 | return temp2; | 336 | return temp2; |
323 | } | 337 | } |
324 | 338 | ||
325 | QString Sheet::popStringStack(QStack<QString> *stackStrings) | 339 | QString Sheet::popStringStack(QStack<QString> *stackStrings) |
326 | { | 340 | { |
327 | if (stackStrings->isEmpty()) | 341 | if (stackStrings->isEmpty()) |
328 | { | 342 | { |
329 | QMessageBox::critical(this, tr("Error"), tr("Syntax error!")); | 343 | QMessageBox::critical(this, tr("Error"), tr("Syntax error!")); |
330 | return "0"; | 344 | return "0"; |
331 | } | 345 | } |
332 | 346 | ||
333 | QString *temp=stackStrings->pop(); | 347 | QString *temp=stackStrings->pop(); |
334 | QString temp2(*temp); | 348 | QString temp2(*temp); |
335 | delete temp; | 349 | delete temp; |
336 | return temp2; | 350 | return temp2; |
337 | } | 351 | } |
338 | 352 | ||
339 | QString Sheet::dataParserHelper(const QString &data) | 353 | QString Sheet::dataParserHelper(const QString &data) |
340 | { | 354 | { |
341 | QStack<QString> stackElements; | 355 | QStack<QString> stackElements; |
342 | QStack<QChar> stackOperators; | 356 | QStack<QChar> stackOperators; |
343 | QString tempElement(""), temp2Element, firstElement, secondElement; | 357 | QString tempElement(""), temp2Element, firstElement, secondElement; |
344 | int paranCount; | 358 | int paranCount; |
345 | 359 | ||
346 | for (unsigned int i=0; i<data.length(); ++i) | 360 | for (unsigned int i=0; i<data.length(); ++i) |
347 | { | 361 | { |
348 | if (data[i]=='+' || data[i]=='-' || data[i]=='*' || data[i]=='/') | 362 | if (data[i]=='+' || data[i]=='-' || data[i]=='*' || data[i]=='/') |
349 | { | 363 | { |
350 | pushStringStack(&stackElements, tempElement); | 364 | pushStringStack(&stackElements, tempElement); |
351 | tempElement=""; | 365 | tempElement=""; |
352 | if (!stackOperators.isEmpty() && getOperatorPriority(*stackOperators.top())>getOperatorPriority(data[i])) | 366 | if (!stackOperators.isEmpty() && getOperatorPriority(*stackOperators.top())>getOperatorPriority(data[i])) |
353 | { | 367 | { |
354 | secondElement=popStringStack(&stackElements); | 368 | secondElement=popStringStack(&stackElements); |
355 | firstElement=popStringStack(&stackElements); | 369 | firstElement=popStringStack(&stackElements); |
356 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); | 370 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); |
357 | } | 371 | } |
358 | pushCharStack(&stackOperators, data[i]); | 372 | pushCharStack(&stackOperators, data[i]); |
359 | } | 373 | } |
360 | else | 374 | else |
361 | if (data[i]==',') | 375 | if (data[i]==',') |
362 | { | 376 | { |
363 | if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement); | 377 | if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement); |
364 | while (!stackOperators.isEmpty()) | 378 | while (!stackOperators.isEmpty()) |
365 | { | 379 | { |
366 | secondElement=popStringStack(&stackElements); | 380 | secondElement=popStringStack(&stackElements); |
367 | firstElement=popStringStack(&stackElements); | 381 | firstElement=popStringStack(&stackElements); |
368 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); | 382 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); |
369 | } | 383 | } |
370 | tempElement=""; | 384 | tempElement=""; |
371 | } | 385 | } |
372 | else | 386 | else |
373 | if (data[i]=='(') | 387 | if (data[i]=='(') |
374 | { | 388 | { |
375 | paranCount=1; | 389 | paranCount=1; |
376 | temp2Element=""; | 390 | temp2Element=""; |
377 | for (++i; paranCount>0; ++i) | 391 | for (++i; paranCount>0; ++i) |
378 | { | 392 | { |
379 | temp2Element+=data[i]; | 393 | temp2Element+=data[i]; |
380 | if (data[i]=='(') ++paranCount; | 394 | if (data[i]=='(') ++paranCount; |
381 | if (data[i]==')') --paranCount; | 395 | if (data[i]==')') --paranCount; |
382 | } | 396 | } |
383 | temp2Element=dataParserHelper(temp2Element.left(temp2Element.length()-1)); | 397 | temp2Element=dataParserHelper(temp2Element.left(temp2Element.length()-1)); |
384 | if (tempElement.isEmpty()) | 398 | if (tempElement.isEmpty()) |
385 | tempElement=temp2Element; | 399 | tempElement=temp2Element; |
386 | else | 400 | else |
387 | tempElement.setNum(calculateFunction(tempElement, temp2Element)); | 401 | tempElement.setNum(calculateFunction(tempElement, temp2Element)); |
388 | --i; | 402 | --i; |
389 | } | 403 | } |
390 | else | 404 | else |
391 | tempElement+=data[i]; | 405 | tempElement+=data[i]; |
392 | } | 406 | } |
393 | if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement); | 407 | if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement); |
394 | while (!stackOperators.isEmpty()) | 408 | while (!stackOperators.isEmpty()) |
395 | { | 409 | { |
396 | secondElement=popStringStack(&stackElements); | 410 | secondElement=popStringStack(&stackElements); |
397 | firstElement=popStringStack(&stackElements); | 411 | firstElement=popStringStack(&stackElements); |
398 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); | 412 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); |
399 | } | 413 | } |
400 | 414 | ||
401 | if (!stackElements.isEmpty()) | 415 | if (!stackElements.isEmpty()) |
402 | tempElement=popStringStack(&stackElements); | 416 | tempElement=popStringStack(&stackElements); |
403 | while (!stackElements.isEmpty()) | 417 | while (!stackElements.isEmpty()) |
404 | tempElement.prepend(popStringStack(&stackElements)+","); | 418 | tempElement.prepend(popStringStack(&stackElements)+","); |
405 | return tempElement; | 419 | return tempElement; |
406 | } | 420 | } |
407 | 421 | ||
408 | QString Sheet::dataParser(const QString &data) | 422 | QString Sheet::dataParser(const QString &data) |
409 | { | 423 | { |
410 | QString strippedData(data); | 424 | QString strippedData(data); |
411 | strippedData.replace(QRegExp("\\s"), ""); | 425 | strippedData.replace(QRegExp("\\s"), ""); |
412 | if (strippedData.isEmpty() || strippedData[0]!='=') return data; | 426 | if (strippedData.isEmpty() || strippedData[0]!='=') return data; |
413 | strippedData=dataParserHelper(strippedData.remove(0, 1).upper().replace(QRegExp(":"), ",")); | 427 | strippedData=dataParserHelper(strippedData.remove(0, 1).upper().replace(QRegExp(":"), ",")); |
414 | 428 | ||
415 | int i=0; | 429 | int i=0; |
416 | QString tempParameter(getParameter(strippedData, i)), result=""; | 430 | QString tempParameter(getParameter(strippedData, i)), result=""; |
417 | do | 431 | do |
418 | { | 432 | { |
419 | result+=","+QString::number(calculateVariable(tempParameter)); | 433 | result+=","+QString::number(calculateVariable(tempParameter)); |
420 | tempParameter=getParameter(strippedData, ++i); | 434 | tempParameter=getParameter(strippedData, ++i); |
421 | } | 435 | } |
422 | while (!tempParameter.isNull()); | 436 | while (!tempParameter.isNull()); |
423 | return result.mid(1); | 437 | return result.mid(1); |
424 | } | 438 | } |
425 | 439 | ||
426 | void Sheet::setData(const QString &data) | 440 | void Sheet::setData(const QString &data) |
427 | { | 441 | { |
428 | setText(currentRow(), currentColumn(), data); | 442 | setText(currentRow(), currentColumn(), data); |
429 | slotCellChanged(currentRow(), currentColumn()); | 443 | slotCellChanged(currentRow(), currentColumn()); |
430 | activateNextCell(); | 444 | activateNextCell(); |
431 | } | 445 | } |
432 | 446 | ||
433 | QString Sheet::getData() | 447 | QString Sheet::getData() |
434 | { | 448 | { |
435 | typeCellData *cellData=findCellData(currentRow(), currentColumn()); | 449 | typeCellData *cellData=findCellData(currentRow(), currentColumn()); |
436 | if (cellData) | 450 | if (cellData) |
437 | return cellData->data; | 451 | return cellData->data; |
438 | return ""; | 452 | return ""; |
439 | } | 453 | } |
440 | 454 | ||
441 | void Sheet::lockClicks(bool lock=TRUE) | 455 | void Sheet::lockClicks(bool lock=TRUE) |
442 | { | 456 | { |
443 | clicksLocked=lock; | 457 | clicksLocked=lock; |
444 | } | 458 | } |
445 | 459 | ||
446 | 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) |
447 | { | 461 | { |
448 | if (selected && row==currentRow() && col==currentColumn()) selected=FALSE; | 462 | if (selected && row==currentRow() && col==currentColumn()) selected=FALSE; |
449 | 463 | ||
450 | int sheetDataCurrent=sheetData.at(); | 464 | int sheetDataCurrent=sheetData.at(); |
451 | typeCellData *cellData=findCellData(row, col); | 465 | typeCellData *cellData=findCellData(row, col); |
452 | if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent); | 466 | if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent); |
453 | if (!cellData) cellData=&defaultCellData; | 467 | if (!cellData) cellData=&defaultCellData; |
454 | if (selected) | 468 | if (selected) |
455 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight()); | 469 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight()); |
456 | else | 470 | else |
457 | { | 471 | { |
458 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base()); | 472 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base()); |
459 | p->fillRect(0, 0, cr.width(), cr.height(), cellData->background); | 473 | p->fillRect(0, 0, cr.width(), cr.height(), cellData->background); |
460 | } | 474 | } |
461 | 475 | ||
462 | QTableItem *cellItem=item(row, col); | 476 | QTableItem *cellItem=item(row, col); |
463 | if (cellItem) | 477 | if (cellItem) |
464 | { | 478 | { |
465 | p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor); | 479 | p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor); |
466 | p->setFont(cellData->font); | 480 | p->setFont(cellData->font); |
467 | 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()); |
468 | } | 482 | } |
469 | 483 | ||
470 | int rx=cr.width()-1, ry=cr.height()-1; | 484 | int rx=cr.width()-1, ry=cr.height()-1; |
471 | QPen pen(p->pen()); | 485 | QPen pen(p->pen()); |
472 | p->setPen(cellData->borders.right); | 486 | p->setPen(cellData->borders.right); |
473 | p->drawLine(rx, 0, rx, ry); | 487 | p->drawLine(rx, 0, rx, ry); |
474 | p->setPen(cellData->borders.bottom); | 488 | p->setPen(cellData->borders.bottom); |
475 | p->drawLine(0, ry, rx, ry); | 489 | p->drawLine(0, ry, rx, ry); |
476 | p->setPen(pen); | 490 | p->setPen(pen); |
477 | } | 491 | } |
478 | 492 | ||
479 | void Sheet::viewportMousePressEvent(QMouseEvent *e) | 493 | void Sheet::viewportMousePressEvent(QMouseEvent *e) |
480 | { | 494 | { |
481 | 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()); |
482 | if (clicksLocked) | 496 | if (clicksLocked) |
483 | { | 497 | { |
484 | if (selectionNo<0) | 498 | if (selectionNo<0) |
485 | { | 499 | { |
486 | clearSelection(); | 500 | clearSelection(); |
487 | QTableSelection newSelection; | 501 | QTableSelection newSelection; |
488 | newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x())); | 502 | newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x())); |
489 | newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol()); | 503 | newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol()); |
490 | selectionNo=addSelection(newSelection); | 504 | selectionNo=addSelection(newSelection); |
491 | } | 505 | } |
492 | } | 506 | } |
493 | else | 507 | else |
494 | QTable::contentsMousePressEvent(&ce); | 508 | QTable::contentsMousePressEvent(&ce); |
495 | } | 509 | } |
496 | 510 | ||
497 | void Sheet::viewportMouseMoveEvent(QMouseEvent *e) | 511 | void Sheet::viewportMouseMoveEvent(QMouseEvent *e) |
498 | { | 512 | { |
499 | 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()); |
500 | if (clicksLocked) | 514 | if (clicksLocked) |
501 | { | 515 | { |
502 | if (selectionNo>=0) | 516 | if (selectionNo>=0) |
503 | { | 517 | { |
504 | QTableSelection oldSelection(selection(selectionNo)); | 518 | QTableSelection oldSelection(selection(selectionNo)); |
505 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); | 519 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); |
506 | if (!(oldSelection==selection(selectionNo))) | 520 | if (!(oldSelection==selection(selectionNo))) |
507 | { | 521 | { |
508 | removeSelection(selectionNo); | 522 | removeSelection(selectionNo); |
509 | selectionNo=addSelection(oldSelection); | 523 | selectionNo=addSelection(oldSelection); |
510 | } | 524 | } |
511 | } | 525 | } |
512 | } | 526 | } |
513 | else | 527 | else |
514 | QTable::contentsMouseMoveEvent(&ce); | 528 | QTable::contentsMouseMoveEvent(&ce); |
515 | } | 529 | } |
516 | 530 | ||
517 | void Sheet::viewportMouseReleaseEvent(QMouseEvent *e) | 531 | void Sheet::viewportMouseReleaseEvent(QMouseEvent *e) |
518 | { | 532 | { |
519 | 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()); |
520 | if (clicksLocked && selectionNo>=0) | 534 | if (clicksLocked && selectionNo>=0) |
521 | { | 535 | { |
522 | QTableSelection oldSelection(selection(selectionNo)); | 536 | QTableSelection oldSelection(selection(selectionNo)); |
523 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); | 537 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); |
524 | removeSelection(selectionNo); | 538 | removeSelection(selectionNo); |
525 | selectionNo=-1; | 539 | selectionNo=-1; |
526 | if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol()) | 540 | if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol()) |
527 | emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1)); | 541 | emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1)); |
528 | else | 542 | else |
529 | 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)); |
530 | } | 544 | } |
531 | else | 545 | else |
532 | QTable::contentsMouseReleaseEvent(&ce); | 546 | QTable::contentsMouseReleaseEvent(&ce); |
533 | } | 547 | } |
534 | 548 | ||
535 | void Sheet::copySheetData(QList<typeCellData> *destSheetData) | 549 | void Sheet::copySheetData(QList<typeCellData> *destSheetData) |
536 | { | 550 | { |
537 | typeCellData *tempCellData, *newCellData; | 551 | typeCellData *tempCellData, *newCellData; |
538 | destSheetData->clear(); | 552 | destSheetData->clear(); |
539 | 553 | ||
540 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 554 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
541 | { | 555 | { |
542 | newCellData=new typeCellData; | 556 | newCellData=new typeCellData; |
543 | *newCellData=*tempCellData; | 557 | *newCellData=*tempCellData; |
544 | destSheetData->append(newCellData); | 558 | destSheetData->append(newCellData); |
545 | } | 559 | } |
546 | } | 560 | } |
547 | 561 | ||
548 | void Sheet::setSheetData(QList<typeCellData> *srcSheetData) | 562 | void Sheet::setSheetData(QList<typeCellData> *srcSheetData) |
549 | { | 563 | { |
550 | typeCellData *tempCellData, *newCellData; | 564 | typeCellData *tempCellData, *newCellData; |
551 | 565 | ||
552 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 566 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
553 | { | 567 | { |
554 | clearCell(tempCellData->row, tempCellData->col); | 568 | clearCell(tempCellData->row, tempCellData->col); |
555 | updateCell(tempCellData->row, tempCellData->col); | 569 | updateCell(tempCellData->row, tempCellData->col); |
556 | } | 570 | } |
557 | sheetData.clear(); | 571 | sheetData.clear(); |
558 | 572 | ||
559 | for (tempCellData=srcSheetData->first(); tempCellData; tempCellData=srcSheetData->next()) | 573 | for (tempCellData=srcSheetData->first(); tempCellData; tempCellData=srcSheetData->next()) |
560 | { | 574 | { |
561 | newCellData=new typeCellData; | 575 | newCellData=new typeCellData; |
562 | *newCellData=*tempCellData; | 576 | *newCellData=*tempCellData; |
563 | sheetData.append(newCellData); | 577 | sheetData.append(newCellData); |
564 | setText(newCellData->row, newCellData->col, dataParser(newCellData->data)); | 578 | setText(newCellData->row, newCellData->col, dataParser(newCellData->data)); |
565 | } | 579 | } |
566 | emit sheetModified(); | 580 | emit sheetModified(); |
567 | } | 581 | } |
568 | 582 | ||
569 | void Sheet::setName(const QString &name) | 583 | void Sheet::setName(const QString &name) |
570 | { | 584 | { |
571 | sheetName=name; | 585 | sheetName=name; |
572 | emit sheetModified(); | 586 | emit sheetModified(); |
573 | } | 587 | } |
574 | 588 | ||
575 | QString Sheet::getName() | 589 | QString Sheet::getName() |
576 | { | 590 | { |
577 | return sheetName; | 591 | return sheetName; |
578 | } | 592 | } |
579 | 593 | ||
580 | void Sheet::setBrush(int row, int col, const QBrush &brush) | 594 | void Sheet::setBrush(int row, int col, const QBrush &brush) |
581 | { | 595 | { |
582 | typeCellData *cellData=findCellData(row, col); | 596 | typeCellData *cellData=findCellData(row, col); |
583 | if (!cellData) cellData=createCellData(row, col); | 597 | if (!cellData) cellData=createCellData(row, col); |
584 | if (cellData) | 598 | if (cellData) |
585 | { | 599 | { |
586 | cellData->background=brush; | 600 | cellData->background=brush; |
587 | emit sheetModified(); | 601 | emit sheetModified(); |
588 | } | 602 | } |
589 | } | 603 | } |
590 | 604 | ||
591 | QBrush Sheet::getBrush(int row, int col) | 605 | QBrush Sheet::getBrush(int row, int col) |
592 | { | 606 | { |
593 | typeCellData *cellData=findCellData(row, col); | 607 | typeCellData *cellData=findCellData(row, col); |
594 | if (!cellData) cellData=&defaultCellData; | 608 | if (!cellData) cellData=&defaultCellData; |
595 | return cellData->background; | 609 | return cellData->background; |
596 | } | 610 | } |
597 | 611 | ||
598 | void Sheet::setTextAlign(int row, int col, Qt::AlignmentFlags flags) | 612 | void Sheet::setTextAlign(int row, int col, Qt::AlignmentFlags flags) |
599 | { | 613 | { |
600 | typeCellData *cellData=findCellData(row, col); | 614 | typeCellData *cellData=findCellData(row, col); |
601 | if (!cellData) cellData=createCellData(row, col); | 615 | if (!cellData) cellData=createCellData(row, col); |
602 | if (cellData) | 616 | if (cellData) |
603 | { | 617 | { |
604 | cellData->alignment=flags; | 618 | cellData->alignment=flags; |
605 | emit sheetModified(); | 619 | emit sheetModified(); |
606 | } | 620 | } |
607 | } | 621 | } |
608 | 622 | ||
609 | Qt::AlignmentFlags Sheet::getAlignment(int row, int col) | 623 | Qt::AlignmentFlags Sheet::getAlignment(int row, int col) |
610 | { | 624 | { |
611 | typeCellData *cellData=findCellData(row, col); | 625 | typeCellData *cellData=findCellData(row, col); |
612 | if (!cellData) cellData=&defaultCellData; | 626 | if (!cellData) cellData=&defaultCellData; |
613 | return cellData->alignment; | 627 | return cellData->alignment; |
614 | } | 628 | } |
615 | 629 | ||
616 | 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) |
617 | { | 631 | { |
618 | typeCellData *cellData=findCellData(row, col); | 632 | typeCellData *cellData=findCellData(row, col); |
619 | if (!cellData) cellData=createCellData(row, col); | 633 | if (!cellData) cellData=createCellData(row, col); |
620 | if (cellData) | 634 | if (cellData) |
621 | { | 635 | { |
622 | cellData->font=font; | 636 | cellData->font=font; |
623 | cellData->fontColor=color; | 637 | cellData->fontColor=color; |
624 | emit sheetModified(); | 638 | emit sheetModified(); |
625 | } | 639 | } |
626 | } | 640 | } |
627 | 641 | ||
628 | QFont Sheet::getFont(int row, int col) | 642 | QFont Sheet::getFont(int row, int col) |
629 | { | 643 | { |
630 | typeCellData *cellData=findCellData(row, col); | 644 | typeCellData *cellData=findCellData(row, col); |
631 | if (!cellData) cellData=&defaultCellData; | 645 | if (!cellData) cellData=&defaultCellData; |
632 | return cellData->font; | 646 | return cellData->font; |
633 | } | 647 | } |
634 | 648 | ||
635 | QColor Sheet::getFontColor(int row, int col) | 649 | QColor Sheet::getFontColor(int row, int col) |
636 | { | 650 | { |
637 | typeCellData *cellData=findCellData(row, col); | 651 | typeCellData *cellData=findCellData(row, col); |
638 | if (!cellData) cellData=&defaultCellData; | 652 | if (!cellData) cellData=&defaultCellData; |
639 | return cellData->fontColor; | 653 | return cellData->fontColor; |
640 | } | 654 | } |
641 | 655 | ||
642 | 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) |
643 | { | 657 | { |
644 | typeCellData *cellData=findCellData(row, col); | 658 | typeCellData *cellData=findCellData(row, col); |
645 | if (!cellData) cellData=createCellData(row, col); | 659 | if (!cellData) cellData=createCellData(row, col); |
646 | if (cellData) | 660 | if (cellData) |
647 | { | 661 | { |
648 | if (vertical) | 662 | if (vertical) |
649 | cellData->borders.right=pen; | 663 | cellData->borders.right=pen; |
650 | else | 664 | else |
651 | cellData->borders.bottom=pen; | 665 | cellData->borders.bottom=pen; |
652 | emit sheetModified(); | 666 | emit sheetModified(); |
653 | } | 667 | } |
654 | } | 668 | } |
655 | 669 | ||
656 | QPen Sheet::getPen(int row, int col, int vertical) | 670 | QPen Sheet::getPen(int row, int col, int vertical) |
657 | { | 671 | { |
658 | typeCellData *cellData=findCellData(row, col); | 672 | typeCellData *cellData=findCellData(row, col); |
659 | if (!cellData) cellData=&defaultCellData; | 673 | if (!cellData) cellData=&defaultCellData; |
660 | return (vertical ? cellData->borders.right : cellData->borders.bottom); | 674 | return (vertical ? cellData->borders.right : cellData->borders.bottom); |
661 | } | 675 | } |
662 | 676 | ||
663 | void Sheet::getSelection(int *row1, int *col1, int *row2, int *col2) | 677 | void Sheet::getSelection(int *row1, int *col1, int *row2, int *col2) |
664 | { | 678 | { |
665 | int selectionNo=currentSelection(); | 679 | int selectionNo=currentSelection(); |
666 | if (selectionNo>=0) | 680 | if (selectionNo>=0) |
667 | { | 681 | { |
668 | QTableSelection selection(selection(selectionNo)); | 682 | QTableSelection selection(selection(selectionNo)); |
669 | *row1=selection.topRow(); | 683 | *row1=selection.topRow(); |
670 | *row2=selection.bottomRow(); | 684 | *row2=selection.bottomRow(); |
671 | *col1=selection.leftCol(); | 685 | *col1=selection.leftCol(); |
672 | *col2=selection.rightCol(); | 686 | *col2=selection.rightCol(); |
673 | } | 687 | } |
674 | else | 688 | else |
675 | { | 689 | { |
676 | *row1=*row2=currentRow(); | 690 | *row1=*row2=currentRow(); |
677 | *col1=*col2=currentColumn(); | 691 | *col1=*col2=currentColumn(); |
678 | } | 692 | } |
679 | } | 693 | } |
680 | 694 | ||
681 | void Sheet::editClear() | 695 | void Sheet::editClear() |
682 | { | 696 | { |
683 | int row1, row2, col1, col2; | 697 | int row1, row2, col1, col2; |
684 | getSelection(&row1, &col1, &row2, &col2); | 698 | getSelection(&row1, &col1, &row2, &col2); |
685 | 699 | ||
686 | int row, col; | 700 | int row, col; |
687 | for (row=row1; row<=row2; ++row) | 701 | for (row=row1; row<=row2; ++row) |
688 | for (col=col1; col<=col2; ++col) | 702 | for (col=col1; col<=col2; ++col) |
689 | { | 703 | { |
690 | setText(row, col, ""); | 704 | setText(row, col, ""); |
691 | slotCellChanged(row, col); | 705 | slotCellChanged(row, col); |
692 | } | 706 | } |
693 | } | 707 | } |
694 | 708 | ||
695 | void Sheet::editCopy() | 709 | void Sheet::editCopy() |
696 | { | 710 | { |
697 | clipboardData.clear(); | 711 | clipboardData.clear(); |
698 | 712 | ||
699 | int row1, row2, col1, col2; | 713 | int row1, row2, col1, col2; |
700 | getSelection(&row1, &col1, &row2, &col2); | 714 | getSelection(&row1, &col1, &row2, &col2); |
701 | 715 | ||
702 | typeCellData *cellData, *newCellData; | 716 | typeCellData *cellData, *newCellData; |
703 | int row, col; | 717 | int row, col; |
704 | for (row=row1; row<=row2; ++row) | 718 | for (row=row1; row<=row2; ++row) |
705 | for (col=col1; col<=col2; ++col) | 719 | for (col=col1; col<=col2; ++col) |
706 | { | 720 | { |
707 | cellData=findCellData(row, col); | 721 | cellData=findCellData(row, col); |
708 | if (cellData) | 722 | if (cellData) |
709 | { | 723 | { |
710 | newCellData=new typeCellData; | 724 | newCellData=new typeCellData; |
711 | *newCellData=*cellData; | 725 | *newCellData=*cellData; |
712 | newCellData->row-=row1; | 726 | newCellData->row-=row1; |
713 | newCellData->col-=col1; | 727 | newCellData->col-=col1; |
714 | clipboardData.append(newCellData); | 728 | clipboardData.append(newCellData); |
715 | } | 729 | } |
716 | } | 730 | } |
717 | } | 731 | } |
718 | 732 | ||
719 | void Sheet::editCut() | 733 | void Sheet::editCut() |
720 | { | 734 | { |
721 | editCopy(); | 735 | editCopy(); |
722 | editClear(); | 736 | editClear(); |
723 | } | 737 | } |
724 | 738 | ||
725 | void Sheet::editPaste(bool onlyContents=FALSE) | 739 | void Sheet::editPaste(bool onlyContents=FALSE) |
726 | { | 740 | { |
727 | int row1=currentRow(), col1=currentColumn(); | 741 | int row1=currentRow(), col1=currentColumn(); |
728 | typeCellData *cellData, *tempCellData; | 742 | typeCellData *cellData, *tempCellData; |
729 | 743 | ||
730 | for (tempCellData=clipboardData.first(); tempCellData; tempCellData=clipboardData.next()) | 744 | for (tempCellData=clipboardData.first(); tempCellData; tempCellData=clipboardData.next()) |
731 | { | 745 | { |
732 | cellData=findCellData(tempCellData->row+row1, tempCellData->col+col1); | 746 | cellData=findCellData(tempCellData->row+row1, tempCellData->col+col1); |
733 | if (!cellData) cellData=createCellData(tempCellData->row+row1, tempCellData->col+col1); | 747 | if (!cellData) cellData=createCellData(tempCellData->row+row1, tempCellData->col+col1); |
734 | if (cellData) | 748 | if (cellData) |
735 | { | 749 | { |
736 | if (onlyContents) | 750 | if (onlyContents) |
737 | cellData->data=tempCellData->data; | 751 | cellData->data=tempCellData->data; |
738 | else | 752 | else |
739 | { | 753 | { |
740 | *cellData=*tempCellData; | 754 | *cellData=*tempCellData; |
741 | cellData->row+=row1; | 755 | cellData->row+=row1; |
742 | cellData->col+=col1; | 756 | cellData->col+=col1; |
743 | } | 757 | } |
744 | setText(cellData->row, cellData->col, dataParser(cellData->data)); | 758 | setText(cellData->row, cellData->col, dataParser(cellData->data)); |
745 | emit sheetModified(); | 759 | emit sheetModified(); |
746 | } | 760 | } |
747 | } | 761 | } |
748 | } | 762 | } |
749 | 763 | ||
750 | void Sheet::insertRows(int no=1, bool allColumns=TRUE) | 764 | void Sheet::insertRows(int no=1, bool allColumns=TRUE) |
751 | { | 765 | { |
752 | setNumRows(numRows()+no); | 766 | setNumRows(numRows()+no); |
753 | 767 | ||
754 | typeCellData *tempCellData; | 768 | typeCellData *tempCellData; |
755 | int row=currentRow(), col=currentColumn(); | 769 | int row=currentRow(), col=currentColumn(); |
756 | 770 | ||
757 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 771 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
758 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) | 772 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) |
759 | { | 773 | { |
760 | clearCell(tempCellData->row, tempCellData->col); | 774 | clearCell(tempCellData->row, tempCellData->col); |
761 | tempCellData->row+=no; | 775 | tempCellData->row+=no; |
762 | } | 776 | } |
763 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 777 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
764 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) | 778 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) |
765 | { | 779 | { |
766 | updateCell(tempCellData->row-no, tempCellData->col); | 780 | updateCell(tempCellData->row-no, tempCellData->col); |
767 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); | 781 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); |
768 | } | 782 | } |
769 | emit sheetModified(); | 783 | emit sheetModified(); |
770 | } | 784 | } |
771 | 785 | ||
772 | void Sheet::insertColumns(int no=1, bool allRows=TRUE) | 786 | void Sheet::insertColumns(int no=1, bool allRows=TRUE) |
773 | { | 787 | { |
774 | int noCols=numCols(); | 788 | int noCols=numCols(); |
775 | int newCols=noCols+no; | 789 | int newCols=noCols+no; |
776 | setNumCols(newCols); | 790 | setNumCols(newCols); |
777 | for (int i=noCols; i<newCols; ++i) | 791 | for (int i=noCols; i<newCols; ++i) |
778 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); | 792 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); |
779 | 793 | ||
780 | typeCellData *tempCellData; | 794 | typeCellData *tempCellData; |
781 | int col=currentColumn(), row=currentRow(); | 795 | int col=currentColumn(), row=currentRow(); |
782 | 796 | ||
783 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 797 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
784 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) | 798 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) |
785 | { | 799 | { |
786 | clearCell(tempCellData->row, tempCellData->col); | 800 | clearCell(tempCellData->row, tempCellData->col); |
787 | tempCellData->col+=no; | 801 | tempCellData->col+=no; |
788 | } | 802 | } |
789 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 803 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
790 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) | 804 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) |
791 | { | 805 | { |
792 | updateCell(tempCellData->row, tempCellData->col-no); | 806 | updateCell(tempCellData->row, tempCellData->col-no); |
793 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); | 807 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); |
794 | } | 808 | } |
795 | emit sheetModified(); | 809 | emit sheetModified(); |
796 | } | 810 | } |
797 | 811 | ||
798 | 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=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE) |
799 | { | 813 | { |
800 | typeCellData *tempCellData; | 814 | typeCellData *tempCellData; |
801 | int row1, col1, row2, col2; | 815 | int row1, col1, row2, col2; |
802 | getSelection(&row1, &col1, &row2, &col2); | 816 | getSelection(&row1, &col1, &row2, &col2); |
803 | bool found=FALSE; | 817 | bool found=FALSE; |
804 | 818 | ||
805 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 819 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
806 | 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)) |
807 | { | 821 | { |
808 | QTableItem *cellItem=item(tempCellData->row, tempCellData->col); | 822 | QTableItem *cellItem=item(tempCellData->row, tempCellData->col); |
809 | 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)) |
810 | { | 824 | { |
811 | if (!found) | 825 | if (!found) |
812 | { | 826 | { |
813 | found=TRUE; | 827 | found=TRUE; |
814 | clearSelection(); | 828 | clearSelection(); |
815 | } | 829 | } |
816 | setCurrentCell(tempCellData->row, tempCellData->col); | 830 | setCurrentCell(tempCellData->row, tempCellData->col); |
817 | if (replace) | 831 | if (replace) |
818 | { | 832 | { |
819 | tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr); | 833 | tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr); |
820 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); | 834 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); |
821 | } | 835 | } |
822 | if (!replace || !replaceAll) break; | 836 | if (!replace || !replaceAll) break; |
823 | } | 837 | } |
824 | } | 838 | } |
825 | 839 | ||
826 | if (found) | 840 | if (found) |
827 | { | 841 | { |
828 | if (replace) | 842 | if (replace) |
829 | slotCellChanged(currentRow(), currentColumn()); | 843 | slotCellChanged(currentRow(), currentColumn()); |
830 | } | 844 | } |
831 | else | 845 | else |
832 | QMessageBox::warning(this, tr("Error"), tr("Search key not found!")); | 846 | QMessageBox::warning(this, tr("Error"), tr("Search key not found!")); |
833 | } | 847 | } |
834 | 848 | ||
835 | // | 849 | // |
836 | // Static functions | 850 | // Static functions |
837 | // | 851 | // |
838 | 852 | ||
839 | QString Sheet::getHeaderString(int section) | 853 | QString Sheet::getHeaderString(int section) |
840 | { | 854 | { |
841 | if (section<1) return ""; | 855 | if (section<1) return ""; |
842 | return getHeaderString((section-1)/26)+QChar('A'+(section-1)%26); | 856 | return getHeaderString((section-1)/26)+QChar('A'+(section-1)%26); |
843 | } | 857 | } |
844 | 858 | ||
845 | int Sheet::getHeaderColumn(const QString §ion) | 859 | int Sheet::getHeaderColumn(const QString §ion) |
846 | { | 860 | { |
847 | if (section.isEmpty()) return 0; | 861 | if (section.isEmpty()) return 0; |
848 | 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; |
849 | } | 863 | } |
diff --git a/noncore/apps/opie-sheet/sheet.h b/noncore/apps/opie-sheet/sheet.h index 02899a0..f78a684 100644 --- a/noncore/apps/opie-sheet/sheet.h +++ b/noncore/apps/opie-sheet/sheet.h | |||
@@ -1,120 +1,134 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #ifndef SHEET_H | 15 | #ifndef SHEET_H |
2 | #define SHEET_H | 16 | #define SHEET_H |
3 | 17 | ||
4 | #include <qtable.h> | 18 | #include <qtable.h> |
5 | #include <qstack.h> | 19 | #include <qstack.h> |
6 | 20 | ||
7 | typedef struct typeCellBorders | 21 | typedef struct typeCellBorders |
8 | { | 22 | { |
9 | QPen right, bottom; | 23 | QPen right, bottom; |
10 | }; | 24 | }; |
11 | 25 | ||
12 | typedef struct typeCellData | 26 | typedef struct typeCellData |
13 | { | 27 | { |
14 | int col, row; | 28 | int col, row; |
15 | typeCellBorders borders; | 29 | typeCellBorders borders; |
16 | QBrush background; | 30 | QBrush background; |
17 | Qt::AlignmentFlags alignment; | 31 | Qt::AlignmentFlags alignment; |
18 | QColor fontColor; | 32 | QColor fontColor; |
19 | QFont font; | 33 | QFont font; |
20 | QString data; | 34 | QString data; |
21 | }; | 35 | }; |
22 | 36 | ||
23 | class Sheet: public QTable | 37 | class Sheet: public QTable |
24 | { | 38 | { |
25 | Q_OBJECT | 39 | Q_OBJECT |
26 | 40 | ||
27 | // Variables | 41 | // Variables |
28 | bool clicksLocked; | 42 | bool clicksLocked; |
29 | int selectionNo; | 43 | int selectionNo; |
30 | typeCellBorders defaultBorders; | 44 | typeCellBorders defaultBorders; |
31 | typeCellData defaultCellData; | 45 | typeCellData defaultCellData; |
32 | 46 | ||
33 | // QT objects | 47 | // QT objects |
34 | QList<typeCellData> sheetData, clipboardData; | 48 | QList<typeCellData> sheetData, clipboardData; |
35 | QString pressedCell, releasedCell, sheetName; | 49 | QString pressedCell, releasedCell, sheetName; |
36 | 50 | ||
37 | // Private functions | 51 | // Private functions |
38 | int getOperatorPriority(char oper); | 52 | int getOperatorPriority(char oper); |
39 | bool findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE); | 53 | bool findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE); |
40 | bool findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2); | 54 | bool findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2); |
41 | double calculateVariable(const QString &variable); | 55 | double calculateVariable(const QString &variable); |
42 | double calculateFunction(const QString &function, const QString ¶meters); | 56 | double calculateFunction(const QString &function, const QString ¶meters); |
43 | QChar popCharStack(QStack<QChar> *stackChars); | 57 | QChar popCharStack(QStack<QChar> *stackChars); |
44 | QString popStringStack(QStack<QString> *stackStrings); | 58 | QString popStringStack(QStack<QString> *stackStrings); |
45 | QString getParameter(const QString ¶meters, int paramNo, bool giveError=FALSE, const QString funcName=""); | 59 | QString getParameter(const QString ¶meters, int paramNo, bool giveError=FALSE, const QString funcName=""); |
46 | QString dataParser(const QString &data); | 60 | QString dataParser(const QString &data); |
47 | QString dataParserHelper(const QString &data); | 61 | QString dataParserHelper(const QString &data); |
48 | typeCellData *createCellData(int row, int col); | 62 | typeCellData *createCellData(int row, int col); |
49 | typeCellData *findCellData(int row, int col); | 63 | typeCellData *findCellData(int row, int col); |
50 | void pushCharStack(QStack<QChar> *stackChars, const QChar &character); | 64 | void pushCharStack(QStack<QChar> *stackChars, const QChar &character); |
51 | void pushStringStack(QStack<QString> *stackStrings, const QString &string); | 65 | void pushStringStack(QStack<QString> *stackStrings, const QString &string); |
52 | 66 | ||
53 | // Sheet/Qt parser functions | 67 | // Sheet/Qt parser functions |
54 | double functionSum(const QString ¶m1, const QString ¶m2); | 68 | double functionSum(const QString ¶m1, const QString ¶m2); |
55 | double functionAvg(const QString ¶m1, const QString ¶m2); | 69 | double functionAvg(const QString ¶m1, const QString ¶m2); |
56 | double functionMax(const QString ¶m1, const QString ¶m2); | 70 | double functionMax(const QString ¶m1, const QString ¶m2); |
57 | double functionMin(const QString ¶m1, const QString ¶m2); | 71 | double functionMin(const QString ¶m1, const QString ¶m2); |
58 | double functionCount(const QString ¶m1, const QString ¶m2); | 72 | double functionCount(const QString ¶m1, const QString ¶m2); |
59 | 73 | ||
60 | // Reimplemented QTable functions | 74 | // Reimplemented QTable functions |
61 | void paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected); | 75 | void paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected); |
62 | void viewportMousePressEvent(QMouseEvent *e); | 76 | void viewportMousePressEvent(QMouseEvent *e); |
63 | void viewportMouseMoveEvent(QMouseEvent *e); | 77 | void viewportMouseMoveEvent(QMouseEvent *e); |
64 | void viewportMouseReleaseEvent(QMouseEvent *e); | 78 | void viewportMouseReleaseEvent(QMouseEvent *e); |
65 | 79 | ||
66 | private slots: | 80 | private slots: |
67 | void slotCellSelected(int row, int col); | 81 | void slotCellSelected(int row, int col); |
68 | void slotCellChanged(int row, int col); | 82 | void slotCellChanged(int row, int col); |
69 | 83 | ||
70 | public: | 84 | public: |
71 | Sheet(int numRows, int numCols, QWidget *parent); | 85 | Sheet(int numRows, int numCols, QWidget *parent); |
72 | ~Sheet(); | 86 | ~Sheet(); |
73 | 87 | ||
74 | void setData(const QString &data); | 88 | void setData(const QString &data); |
75 | QString getData(); | 89 | QString getData(); |
76 | 90 | ||
77 | void setName(const QString &data); | 91 | void setName(const QString &data); |
78 | QString getName(); | 92 | QString getName(); |
79 | 93 | ||
80 | void setPen(int row, int col, int vertical, const QPen &pen); | 94 | void setPen(int row, int col, int vertical, const QPen &pen); |
81 | QPen getPen(int row, int col, int vertical); | 95 | QPen getPen(int row, int col, int vertical); |
82 | 96 | ||
83 | void setBrush(int row, int col, const QBrush &brush); | 97 | void setBrush(int row, int col, const QBrush &brush); |
84 | QBrush getBrush(int row, int col); | 98 | QBrush getBrush(int row, int col); |
85 | 99 | ||
86 | void setTextAlign(int row, int col, Qt::AlignmentFlags flags); | 100 | void setTextAlign(int row, int col, Qt::AlignmentFlags flags); |
87 | Qt::AlignmentFlags getAlignment(int row, int col); | 101 | Qt::AlignmentFlags getAlignment(int row, int col); |
88 | 102 | ||
89 | void setTextFont(int row, int col, const QFont &font, const QColor &color); | 103 | void setTextFont(int row, int col, const QFont &font, const QColor &color); |
90 | QFont getFont(int row, int col); | 104 | QFont getFont(int row, int col); |
91 | QColor getFontColor(int row, int col); | 105 | QColor getFontColor(int row, int col); |
92 | 106 | ||
93 | void lockClicks(bool lock=TRUE); | 107 | void lockClicks(bool lock=TRUE); |
94 | void copySheetData(QList<typeCellData> *destSheetData); | 108 | void copySheetData(QList<typeCellData> *destSheetData); |
95 | void setSheetData(QList<typeCellData> *srcSheetData); | 109 | void setSheetData(QList<typeCellData> *srcSheetData); |
96 | void getSelection(int *row1, int *col1, int *row2, int *col2); | 110 | void getSelection(int *row1, int *col1, int *row2, int *col2); |
97 | 111 | ||
98 | void insertRows(int no=1, bool allColumns=TRUE); | 112 | void insertRows(int no=1, bool allColumns=TRUE); |
99 | void insertColumns(int no=1, bool allRows=TRUE); | 113 | void insertColumns(int no=1, bool allRows=TRUE); |
100 | 114 | ||
101 | void dataFindReplace(const QString &find, const QString &replace, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE); | 115 | void dataFindReplace(const QString &find, const QString &replace, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE); |
102 | 116 | ||
103 | // Static functions | 117 | // Static functions |
104 | static int getHeaderColumn(const QString §ion); | 118 | static int getHeaderColumn(const QString §ion); |
105 | static QString getHeaderString(int section); | 119 | static QString getHeaderString(int section); |
106 | 120 | ||
107 | public slots: | 121 | public slots: |
108 | void editCut(); | 122 | void editCut(); |
109 | void editCopy(); | 123 | void editCopy(); |
110 | void editPaste(bool onlyContents=FALSE); | 124 | void editPaste(bool onlyContents=FALSE); |
111 | void editClear(); | 125 | void editClear(); |
112 | void swapCells(int row1, int col1, int row2, int col2); | 126 | void swapCells(int row1, int col1, int row2, int col2); |
113 | 127 | ||
114 | signals: | 128 | signals: |
115 | void currentDataChanged(const QString &data); | 129 | void currentDataChanged(const QString &data); |
116 | void cellClicked(const QString &cell); | 130 | void cellClicked(const QString &cell); |
117 | void sheetModified(); | 131 | void sheetModified(); |
118 | }; | 132 | }; |
119 | 133 | ||
120 | #endif | 134 | #endif |
diff --git a/noncore/apps/opie-sheet/sortdlg.cpp b/noncore/apps/opie-sheet/sortdlg.cpp index f46562e..4f18fd3 100644 --- a/noncore/apps/opie-sheet/sortdlg.cpp +++ b/noncore/apps/opie-sheet/sortdlg.cpp | |||
@@ -1,178 +1,192 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #include <qlabel.h> | 15 | #include <qlabel.h> |
2 | #include <qradiobutton.h> | 16 | #include <qradiobutton.h> |
3 | #include <qmessagebox.h> | 17 | #include <qmessagebox.h> |
4 | #include "sortdlg.h" | 18 | #include "sortdlg.h" |
5 | 19 | ||
6 | SortDialog::SortDialog(QWidget *parent=0) | 20 | SortDialog::SortDialog(QWidget *parent=0) |
7 | :QDialog(parent, 0, TRUE) | 21 | :QDialog(parent, 0, TRUE) |
8 | { | 22 | { |
9 | // Main widget | 23 | // Main widget |
10 | tabs=new QTabWidget(this); | 24 | tabs=new QTabWidget(this); |
11 | widgetSort=new QWidget(tabs); | 25 | widgetSort=new QWidget(tabs); |
12 | widgetOptions=new QWidget(tabs); | 26 | widgetOptions=new QWidget(tabs); |
13 | tabs->addTab(widgetSort, tr("&Sort")); | 27 | tabs->addTab(widgetSort, tr("&Sort")); |
14 | tabs->addTab(widgetOptions, tr("&Options")); | 28 | tabs->addTab(widgetOptions, tr("&Options")); |
15 | 29 | ||
16 | // Sort tab | 30 | // Sort tab |
17 | comboFieldA=createFieldCombo(tr("&Sort by"), 10); | 31 | comboFieldA=createFieldCombo(tr("&Sort by"), 10); |
18 | groupOrderA=createOrderButtons(10); | 32 | groupOrderA=createOrderButtons(10); |
19 | comboFieldB=createFieldCombo(tr("&Then by"), 90); | 33 | comboFieldB=createFieldCombo(tr("&Then by"), 90); |
20 | groupOrderB=createOrderButtons(90); | 34 | groupOrderB=createOrderButtons(90); |
21 | comboFieldC=createFieldCombo(tr("Then &by"), 170); | 35 | comboFieldC=createFieldCombo(tr("Then &by"), 170); |
22 | groupOrderC=createOrderButtons(170); | 36 | groupOrderC=createOrderButtons(170); |
23 | 37 | ||
24 | // Options tab | 38 | // Options tab |
25 | checkCase=new QCheckBox(tr("&Case Sensitive"), widgetOptions); | 39 | checkCase=new QCheckBox(tr("&Case Sensitive"), widgetOptions); |
26 | checkCase->setGeometry(10, 10, 215, 20); | 40 | checkCase->setGeometry(10, 10, 215, 20); |
27 | checkCase->setChecked(TRUE); | 41 | checkCase->setChecked(TRUE); |
28 | 42 | ||
29 | groupDirection=new QVButtonGroup(tr("&Direction"), widgetOptions); | 43 | groupDirection=new QVButtonGroup(tr("&Direction"), widgetOptions); |
30 | groupDirection->setGeometry(10, 40, 215, 70); | 44 | groupDirection->setGeometry(10, 40, 215, 70); |
31 | QRadioButton *radio=new QRadioButton(tr("&Top to bottom (rows)"), groupDirection); | 45 | QRadioButton *radio=new QRadioButton(tr("&Top to bottom (rows)"), groupDirection); |
32 | radio=new QRadioButton(tr("&Left to right (columns)"), groupDirection); | 46 | radio=new QRadioButton(tr("&Left to right (columns)"), groupDirection); |
33 | groupDirection->setButton(0); | 47 | groupDirection->setButton(0); |
34 | connect(groupDirection, SIGNAL(clicked(int)), this, SLOT(directionChanged(int))); | 48 | connect(groupDirection, SIGNAL(clicked(int)), this, SLOT(directionChanged(int))); |
35 | 49 | ||
36 | // Main widget | 50 | // Main widget |
37 | box=new QVBoxLayout(this); | 51 | box=new QVBoxLayout(this); |
38 | box->addWidget(tabs); | 52 | box->addWidget(tabs); |
39 | 53 | ||
40 | setCaption(tr("Sort")); | 54 | setCaption(tr("Sort")); |
41 | } | 55 | } |
42 | 56 | ||
43 | SortDialog::~SortDialog() | 57 | SortDialog::~SortDialog() |
44 | { | 58 | { |
45 | } | 59 | } |
46 | 60 | ||
47 | QComboBox *SortDialog::createFieldCombo(const QString &caption, int y) | 61 | QComboBox *SortDialog::createFieldCombo(const QString &caption, int y) |
48 | { | 62 | { |
49 | QLabel *label=new QLabel(caption, widgetSort); | 63 | QLabel *label=new QLabel(caption, widgetSort); |
50 | label->setGeometry(10, y+5, 215, 20); | 64 | label->setGeometry(10, y+5, 215, 20); |
51 | QComboBox *combo=new QComboBox(FALSE, widgetSort); | 65 | QComboBox *combo=new QComboBox(FALSE, widgetSort); |
52 | combo->setGeometry(10, y+35, 105, 20); | 66 | combo->setGeometry(10, y+35, 105, 20); |
53 | label->setBuddy(combo); | 67 | label->setBuddy(combo); |
54 | return combo; | 68 | return combo; |
55 | } | 69 | } |
56 | 70 | ||
57 | QVButtonGroup *SortDialog::createOrderButtons(int y) | 71 | QVButtonGroup *SortDialog::createOrderButtons(int y) |
58 | { | 72 | { |
59 | QVButtonGroup *group=new QVButtonGroup(widgetSort); | 73 | QVButtonGroup *group=new QVButtonGroup(widgetSort); |
60 | group->setGeometry(125, y, 100, 60); | 74 | group->setGeometry(125, y, 100, 60); |
61 | QRadioButton *radio=new QRadioButton(tr("&Ascending"), group); | 75 | QRadioButton *radio=new QRadioButton(tr("&Ascending"), group); |
62 | radio=new QRadioButton(tr("&Descending"), group); | 76 | radio=new QRadioButton(tr("&Descending"), group); |
63 | group->setButton(0); | 77 | group->setButton(0); |
64 | return group; | 78 | return group; |
65 | } | 79 | } |
66 | 80 | ||
67 | void SortDialog::directionChanged(int id) | 81 | void SortDialog::directionChanged(int id) |
68 | { | 82 | { |
69 | direction=id; | 83 | direction=id; |
70 | fillFieldCombo(comboFieldA); | 84 | fillFieldCombo(comboFieldA); |
71 | fillFieldCombo(comboFieldB); | 85 | fillFieldCombo(comboFieldB); |
72 | fillFieldCombo(comboFieldC); | 86 | fillFieldCombo(comboFieldC); |
73 | } | 87 | } |
74 | 88 | ||
75 | void SortDialog::fillFieldCombo(QComboBox *combo) | 89 | void SortDialog::fillFieldCombo(QComboBox *combo) |
76 | { | 90 | { |
77 | combo->clear(); | 91 | combo->clear(); |
78 | if (direction) | 92 | if (direction) |
79 | for (int row=row1; row<=row2; ++row) | 93 | for (int row=row1; row<=row2; ++row) |
80 | combo->insertItem("Row "+QString::number(row+1)); | 94 | combo->insertItem("Row "+QString::number(row+1)); |
81 | else | 95 | else |
82 | for (int col=col1; col<=col2; ++col) | 96 | for (int col=col1; col<=col2; ++col) |
83 | combo->insertItem("Column "+Sheet::getHeaderString(col+1)); | 97 | combo->insertItem("Column "+Sheet::getHeaderString(col+1)); |
84 | } | 98 | } |
85 | 99 | ||
86 | int SortDialog::exec(Sheet *s) | 100 | int SortDialog::exec(Sheet *s) |
87 | { | 101 | { |
88 | sheet=s; | 102 | sheet=s; |
89 | sheet->getSelection(&row1, &col1, &row2, &col2); | 103 | sheet->getSelection(&row1, &col1, &row2, &col2); |
90 | 104 | ||
91 | direction=0; | 105 | direction=0; |
92 | fillFieldCombo(comboFieldA); | 106 | fillFieldCombo(comboFieldA); |
93 | fillFieldCombo(comboFieldB); | 107 | fillFieldCombo(comboFieldB); |
94 | fillFieldCombo(comboFieldC); | 108 | fillFieldCombo(comboFieldC); |
95 | 109 | ||
96 | if (row1==row2 && col1==col2) | 110 | if (row1==row2 && col1==col2) |
97 | { | 111 | { |
98 | QMessageBox::warning(this, tr("Error"), tr("One cell cannot be sorted!")); | 112 | QMessageBox::warning(this, tr("Error"), tr("One cell cannot be sorted!")); |
99 | return QDialog::Rejected; | 113 | return QDialog::Rejected; |
100 | } | 114 | } |
101 | if (QDialog::exec()==QDialog::Accepted) | 115 | if (QDialog::exec()==QDialog::Accepted) |
102 | { | 116 | { |
103 | QString field1S=comboFieldA->currentText(), field2S=comboFieldA->currentText(), field3S=comboFieldA->currentText(); | 117 | QString field1S=comboFieldA->currentText(), field2S=comboFieldA->currentText(), field3S=comboFieldA->currentText(); |
104 | field1S=field1S.mid(field1S.find(' ')+1); | 118 | field1S=field1S.mid(field1S.find(' ')+1); |
105 | field2S=field2S.mid(field2S.find(' ')+1); | 119 | field2S=field2S.mid(field2S.find(' ')+1); |
106 | field3S=field3S.mid(field3S.find(' ')+1); | 120 | field3S=field3S.mid(field3S.find(' ')+1); |
107 | int field1, field2, field3; | 121 | int field1, field2, field3; |
108 | if (direction) | 122 | if (direction) |
109 | { | 123 | { |
110 | field1=field1S.toInt()-1; | 124 | field1=field1S.toInt()-1; |
111 | field2=field2S.toInt()-1; | 125 | field2=field2S.toInt()-1; |
112 | field3=field3S.toInt()-1; | 126 | field3=field3S.toInt()-1; |
113 | int i, j; | 127 | int i, j; |
114 | for (i=col2; i>=col1; --i) | 128 | for (i=col2; i>=col1; --i) |
115 | for (j=col1+1; j<=i; ++j) | 129 | for (j=col1+1; j<=i; ++j) |
116 | { | 130 | { |
117 | bool swap=FALSE; | 131 | bool swap=FALSE; |
118 | 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()); |
119 | if (compareResult>0) swap=TRUE; | 133 | if (compareResult>0) swap=TRUE; |
120 | else if (compareResult==0) | 134 | else if (compareResult==0) |
121 | { | 135 | { |
122 | compareResult=compareItems(s->item(field2, j-1), s->item(field2, j), groupOrderA->id(groupOrderB->selected()), checkCase->isChecked()); | 136 | compareResult=compareItems(s->item(field2, j-1), s->item(field2, j), groupOrderA->id(groupOrderB->selected()), checkCase->isChecked()); |
123 | if (compareResult>0) swap=TRUE; | 137 | if (compareResult>0) swap=TRUE; |
124 | else if (compareResult==0) | 138 | else if (compareResult==0) |
125 | { | 139 | { |
126 | compareResult=compareItems(s->item(field3, j-1), s->item(field3, j), groupOrderA->id(groupOrderC->selected()), checkCase->isChecked()); | 140 | compareResult=compareItems(s->item(field3, j-1), s->item(field3, j), groupOrderA->id(groupOrderC->selected()), checkCase->isChecked()); |
127 | if (compareResult>0) swap=TRUE; | 141 | if (compareResult>0) swap=TRUE; |
128 | } | 142 | } |
129 | } | 143 | } |
130 | if (swap) | 144 | if (swap) |
131 | for (int row=row1; row<=row2; ++row) | 145 | for (int row=row1; row<=row2; ++row) |
132 | s->swapCells(row, j-1, row, j); | 146 | s->swapCells(row, j-1, row, j); |
133 | } | 147 | } |
134 | } | 148 | } |
135 | else | 149 | else |
136 | { | 150 | { |
137 | field1=Sheet::getHeaderColumn(field1S)-1; | 151 | field1=Sheet::getHeaderColumn(field1S)-1; |
138 | field2=Sheet::getHeaderColumn(field2S)-1; | 152 | field2=Sheet::getHeaderColumn(field2S)-1; |
139 | field3=Sheet::getHeaderColumn(field3S)-1; | 153 | field3=Sheet::getHeaderColumn(field3S)-1; |
140 | int i, j; | 154 | int i, j; |
141 | for (i=row2; i>=row1; --i) | 155 | for (i=row2; i>=row1; --i) |
142 | for (j=row1+1; j<=i; ++j) | 156 | for (j=row1+1; j<=i; ++j) |
143 | { | 157 | { |
144 | bool swap=FALSE; | 158 | bool swap=FALSE; |
145 | 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()); |
146 | if (compareResult>0) swap=TRUE; | 160 | if (compareResult>0) swap=TRUE; |
147 | else if (compareResult==0) | 161 | else if (compareResult==0) |
148 | { | 162 | { |
149 | compareResult=compareItems(s->item(j-1, field2), s->item(j, field2), groupOrderA->id(groupOrderB->selected()), checkCase->isChecked()); | 163 | compareResult=compareItems(s->item(j-1, field2), s->item(j, field2), groupOrderA->id(groupOrderB->selected()), checkCase->isChecked()); |
150 | if (compareResult>0) swap=TRUE; | 164 | if (compareResult>0) swap=TRUE; |
151 | else if (compareResult==0) | 165 | else if (compareResult==0) |
152 | { | 166 | { |
153 | compareResult=compareItems(s->item(j-1, field3), s->item(j, field3), groupOrderA->id(groupOrderC->selected()), checkCase->isChecked()); | 167 | compareResult=compareItems(s->item(j-1, field3), s->item(j, field3), groupOrderA->id(groupOrderC->selected()), checkCase->isChecked()); |
154 | if (compareResult>0) swap=TRUE; | 168 | if (compareResult>0) swap=TRUE; |
155 | } | 169 | } |
156 | } | 170 | } |
157 | if (swap) | 171 | if (swap) |
158 | for (int col=col1; col<=col2; ++col) | 172 | for (int col=col1; col<=col2; ++col) |
159 | s->swapCells(j-1, col, j, col); | 173 | s->swapCells(j-1, col, j, col); |
160 | } | 174 | } |
161 | } | 175 | } |
162 | return QDialog::Accepted; | 176 | return QDialog::Accepted; |
163 | } | 177 | } |
164 | return QDialog::Rejected; | 178 | return QDialog::Rejected; |
165 | } | 179 | } |
166 | 180 | ||
167 | int SortDialog::compareItems(QTableItem *item1, QTableItem *item2, int descending=0, bool caseSensitive=TRUE) | 181 | int SortDialog::compareItems(QTableItem *item1, QTableItem *item2, int descending=0, bool caseSensitive=TRUE) |
168 | { | 182 | { |
169 | int result=0; | 183 | int result=0; |
170 | if (item1) | 184 | if (item1) |
171 | { | 185 | { |
172 | if (item2) result=(caseSensitive ? item1->text().compare(item2->text()) : item1->text().upper().compare(item2->text().upper())); | 186 | if (item2) result=(caseSensitive ? item1->text().compare(item2->text()) : item1->text().upper().compare(item2->text().upper())); |
173 | else result=-1; | 187 | else result=-1; |
174 | } | 188 | } |
175 | else | 189 | else |
176 | if (item2) result=1; | 190 | if (item2) result=1; |
177 | return (descending ? -result : result); | 191 | return (descending ? -result : result); |
178 | } | 192 | } |
diff --git a/noncore/apps/opie-sheet/sortdlg.h b/noncore/apps/opie-sheet/sortdlg.h index 2c99f02..b3699a9 100644 --- a/noncore/apps/opie-sheet/sortdlg.h +++ b/noncore/apps/opie-sheet/sortdlg.h | |||
@@ -1,45 +1,59 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #ifndef SORTDLG_H | 15 | #ifndef SORTDLG_H |
2 | #define SORTDLG_H | 16 | #define SORTDLG_H |
3 | 17 | ||
4 | #include <qdialog.h> | 18 | #include <qdialog.h> |
5 | #include <qtabwidget.h> | 19 | #include <qtabwidget.h> |
6 | #include <qlayout.h> | 20 | #include <qlayout.h> |
7 | #include <qcombobox.h> | 21 | #include <qcombobox.h> |
8 | #include <qcheckbox.h> | 22 | #include <qcheckbox.h> |
9 | #include <qpushbutton.h> | 23 | #include <qpushbutton.h> |
10 | #include <qvbuttongroup.h> | 24 | #include <qvbuttongroup.h> |
11 | #include "sheet.h" | 25 | #include "sheet.h" |
12 | 26 | ||
13 | class SortDialog: public QDialog | 27 | class SortDialog: public QDialog |
14 | { | 28 | { |
15 | Q_OBJECT | 29 | Q_OBJECT |
16 | 30 | ||
17 | // QT objects | 31 | // QT objects |
18 | QBoxLayout *box; | 32 | QBoxLayout *box; |
19 | QTabWidget *tabs; | 33 | QTabWidget *tabs; |
20 | QWidget *widgetSort, *widgetOptions; | 34 | QWidget *widgetSort, *widgetOptions; |
21 | QVButtonGroup *groupOrderA, *groupOrderB, *groupOrderC, *groupDirection; | 35 | QVButtonGroup *groupOrderA, *groupOrderB, *groupOrderC, *groupDirection; |
22 | QCheckBox *checkCase; | 36 | QCheckBox *checkCase; |
23 | QComboBox *comboFieldA, *comboFieldB, *comboFieldC; | 37 | QComboBox *comboFieldA, *comboFieldB, *comboFieldC; |
24 | 38 | ||
25 | // Other objects & variables | 39 | // Other objects & variables |
26 | int row1, col1, row2, col2, direction; | 40 | int row1, col1, row2, col2, direction; |
27 | Sheet *sheet; | 41 | Sheet *sheet; |
28 | 42 | ||
29 | // Private functions | 43 | // Private functions |
30 | QVButtonGroup *createOrderButtons(int y); | 44 | QVButtonGroup *createOrderButtons(int y); |
31 | QComboBox *createFieldCombo(const QString &caption, int y); | 45 | QComboBox *createFieldCombo(const QString &caption, int y); |
32 | void fillFieldCombo(QComboBox *combo); | 46 | void fillFieldCombo(QComboBox *combo); |
33 | int compareItems(QTableItem *item1, QTableItem *item2, int descending=0, bool caseSensitive=TRUE); | 47 | int compareItems(QTableItem *item1, QTableItem *item2, int descending=0, bool caseSensitive=TRUE); |
34 | 48 | ||
35 | private slots: | 49 | private slots: |
36 | void directionChanged(int id); | 50 | void directionChanged(int id); |
37 | 51 | ||
38 | public: | 52 | public: |
39 | SortDialog(QWidget *parent=0); | 53 | SortDialog(QWidget *parent=0); |
40 | ~SortDialog(); | 54 | ~SortDialog(); |
41 | 55 | ||
42 | int exec(Sheet *s); | 56 | int exec(Sheet *s); |
43 | }; | 57 | }; |
44 | 58 | ||
45 | #endif | 59 | #endif |
diff --git a/noncore/apps/opie-sheet/textdlg.cpp b/noncore/apps/opie-sheet/textdlg.cpp index 8245fe4..0810eb2 100644 --- a/noncore/apps/opie-sheet/textdlg.cpp +++ b/noncore/apps/opie-sheet/textdlg.cpp | |||
@@ -1,32 +1,46 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #include "textdlg.h" | 15 | #include "textdlg.h" |
2 | 16 | ||
3 | TextDialog::TextDialog(QWidget *parent=0) | 17 | TextDialog::TextDialog(QWidget *parent=0) |
4 | :QDialog(parent, 0, TRUE) | 18 | :QDialog(parent, 0, TRUE) |
5 | { | 19 | { |
6 | edit=new QLineEdit(this); | 20 | edit=new QLineEdit(this); |
7 | edit->setGeometry(90, 10, 100, 25); | 21 | edit->setGeometry(90, 10, 100, 25); |
8 | 22 | ||
9 | label=new QLabel(this); | 23 | label=new QLabel(this); |
10 | label->setGeometry(10, 10, 70, 25); | 24 | label->setGeometry(10, 10, 70, 25); |
11 | label->setBuddy(edit); | 25 | label->setBuddy(edit); |
12 | 26 | ||
13 | resize(200, 45); | 27 | resize(200, 45); |
14 | } | 28 | } |
15 | 29 | ||
16 | TextDialog::~TextDialog() | 30 | TextDialog::~TextDialog() |
17 | { | 31 | { |
18 | } | 32 | } |
19 | 33 | ||
20 | int TextDialog::exec(const QString &caption, const QString &text, const QString &value="") | 34 | int TextDialog::exec(const QString &caption, const QString &text, const QString &value="") |
21 | { | 35 | { |
22 | setCaption(caption); | 36 | setCaption(caption); |
23 | label->setText(text); | 37 | label->setText(text); |
24 | edit->setText(value); | 38 | edit->setText(value); |
25 | 39 | ||
26 | return QDialog::exec(); | 40 | return QDialog::exec(); |
27 | } | 41 | } |
28 | 42 | ||
29 | QString TextDialog::getValue() | 43 | QString TextDialog::getValue() |
30 | { | 44 | { |
31 | return edit->text(); | 45 | return edit->text(); |
32 | } | 46 | } |
diff --git a/noncore/apps/opie-sheet/textdlg.h b/noncore/apps/opie-sheet/textdlg.h index f948228..78ef580 100644 --- a/noncore/apps/opie-sheet/textdlg.h +++ b/noncore/apps/opie-sheet/textdlg.h | |||
@@ -1,24 +1,38 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
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 * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /* | ||
11 | * Opie Sheet (formerly Sheet/Qt) | ||
12 | * by Serdar Ozler <sozler@sitebest.com> | ||
13 | */ | ||
14 | |||
1 | #ifndef TEXTDLG_H | 15 | #ifndef TEXTDLG_H |
2 | #define TEXTDLG_H | 16 | #define TEXTDLG_H |
3 | 17 | ||
4 | #include <qdialog.h> | 18 | #include <qdialog.h> |
5 | #include <qlabel.h> | 19 | #include <qlabel.h> |
6 | #include <qlineedit.h> | 20 | #include <qlineedit.h> |
7 | 21 | ||
8 | class TextDialog: public QDialog | 22 | class TextDialog: public QDialog |
9 | { | 23 | { |
10 | Q_OBJECT | 24 | Q_OBJECT |
11 | 25 | ||
12 | // QT objects | 26 | // QT objects |
13 | QLabel *label; | 27 | QLabel *label; |
14 | QLineEdit *edit; | 28 | QLineEdit *edit; |
15 | 29 | ||
16 | public: | 30 | public: |
17 | TextDialog(QWidget *parent=0); | 31 | TextDialog(QWidget *parent=0); |
18 | ~TextDialog(); | 32 | ~TextDialog(); |
19 | 33 | ||
20 | int exec(const QString &caption, const QString &text, const QString &value=""); | 34 | int exec(const QString &caption, const QString &text, const QString &value=""); |
21 | QString getValue(); | 35 | QString getValue(); |
22 | }; | 36 | }; |
23 | 37 | ||
24 | #endif | 38 | #endif |