File indexing completed on 2024-05-12 16:35:36
0001 /* This file is part of the KDE project 0002 0003 Copyright (C) 2006 Fredrik Edemar <f_edemar@linux.se> 0004 Copyright 2004 Ariya Hidayat <ariya@kde.org> 0005 Copyright 2002-2003 Joseph Wenninger <jowenn@kde.org> 0006 Copyright 2002 John Dailey <dailey@vt.edu> 0007 Copyright 2001-2002 Laurent Montel <montel@kde.org> 0008 Copyright 2001 Philipp Mueller <philipp.mueller@gmx.de> 0009 Copyright 2000 Simon Hausmann <hausmann@kde.org> 0010 Copyright 1999 Torben Weis <weis@kde.org> 0011 0012 This library is free software; you can redistribute it and/or 0013 modify it under the terms of the GNU Library General Public 0014 License as published by the Free Software Foundation; either 0015 version 2 of the License, or (at your option) any later version. 0016 0017 This library is distributed in the hope that it will be useful, 0018 but WITHOUT ANY WARRANTY; without even the implied warranty of 0019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0020 Library General Public License for more details. 0021 0022 You should have received a copy of the GNU Library General Public License 0023 along with this library; see the file COPYING.LIB. If not, write to 0024 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0025 Boston, MA 02110-1301, USA. 0026 */ 0027 0028 // Local 0029 #include "ViewAdaptor.h" 0030 0031 #include "part/Doc.h" 0032 #include "Map.h" 0033 #include "ui/Selection.h" 0034 #include "Sheet.h" 0035 #include "part/View.h" 0036 #include "part/Canvas.h" 0037 #include "MapAdaptor.h" 0038 0039 // commands 0040 #include "commands/BorderColorCommand.h" 0041 #include "commands/CommentCommand.h" 0042 #include "commands/StyleCommand.h" 0043 0044 #include <KoSelection.h> 0045 0046 using namespace Calligra::Sheets; 0047 0048 /************************************************ 0049 * 0050 * ViewAdaptor 0051 * 0052 ************************************************/ 0053 0054 ViewAdaptor::ViewAdaptor(View* t) 0055 : QDBusAbstractAdaptor(t) 0056 { 0057 setAutoRelaySignals(true); 0058 m_view = t; 0059 0060 Q_ASSERT(t->selection()); 0061 connect(t->selection(), SIGNAL(changed(Region)), this, SIGNAL(selectionChanged())); 0062 } 0063 0064 ViewAdaptor::~ViewAdaptor() 0065 { 0066 } 0067 0068 QString ViewAdaptor::doc() const 0069 { 0070 return m_view->doc()->objectName(); 0071 } 0072 0073 QString ViewAdaptor::map() const 0074 { 0075 return m_view->doc()->map()->objectName(); 0076 } 0077 0078 QString ViewAdaptor::sheet() const 0079 { 0080 return m_view->activeSheet()->objectName(); 0081 } 0082 0083 void ViewAdaptor::changeNbOfRecentFiles(int _nb) 0084 { 0085 if (_nb < 0) 0086 return; 0087 m_view->changeNbOfRecentFiles(_nb); 0088 } 0089 0090 0091 void ViewAdaptor::hide() 0092 { 0093 m_view->hide(); 0094 } 0095 0096 void ViewAdaptor::show() 0097 { 0098 m_view->show(); 0099 } 0100 0101 #if 0 // -> cell tool 0102 void ViewAdaptor::find() 0103 { 0104 m_view->find(); 0105 } 0106 0107 void ViewAdaptor::replace() 0108 { 0109 m_view->replace(); 0110 } 0111 0112 void ViewAdaptor::conditional() 0113 { 0114 m_view->conditional(); 0115 } 0116 0117 void ViewAdaptor::validity() 0118 { 0119 m_view->validity(); 0120 } 0121 0122 void ViewAdaptor::insertSeries() 0123 { 0124 m_view->insertSeries(); 0125 } 0126 0127 void ViewAdaptor::insertHyperlink() 0128 { 0129 m_view->insertHyperlink(); 0130 } 0131 0132 void ViewAdaptor::gotoCell() 0133 { 0134 m_view->gotoCell(); 0135 } 0136 0137 void ViewAdaptor::changeAngle() 0138 { 0139 m_view->changeAngle(); 0140 } 0141 #endif 0142 0143 void ViewAdaptor::preference() 0144 { 0145 m_view->preference(); 0146 } 0147 0148 void ViewAdaptor::nextSheet() 0149 { 0150 m_view->nextSheet(); 0151 } 0152 0153 bool ViewAdaptor::showSheet(const QString& sheetName) 0154 { 0155 Sheet *const sheet = m_view->doc()->map()->findSheet(sheetName); 0156 if (!sheet) { 0157 debugSheets << "Unknown sheet" << sheetName; 0158 return false; 0159 } 0160 m_view->selection()->emitCloseEditor(true); // save changes 0161 m_view->setActiveSheet(sheet); 0162 return true; 0163 } 0164 0165 void ViewAdaptor::previousSheet() 0166 { 0167 m_view->previousSheet(); 0168 } 0169 0170 #if 0 // -> cell tool 0171 void ViewAdaptor::sortList() 0172 { 0173 m_view->sortList(); 0174 } 0175 0176 void ViewAdaptor::setAreaName() 0177 { 0178 m_view->setAreaName(); 0179 } 0180 0181 void ViewAdaptor::showAreaName() 0182 { 0183 m_view->namedAreaDialog(); 0184 } 0185 0186 void ViewAdaptor::mergeCell() 0187 { 0188 m_view->mergeCell(); 0189 } 0190 0191 void ViewAdaptor::dissociateCell() 0192 { 0193 m_view->dissociateCell(); 0194 } 0195 0196 void ViewAdaptor::consolidate() 0197 { 0198 m_view->consolidate(); 0199 } 0200 0201 void ViewAdaptor::deleteColumn() 0202 { 0203 m_view->deleteColumn(); 0204 } 0205 0206 void ViewAdaptor::insertColumn() 0207 { 0208 m_view->insertColumn(); 0209 } 0210 0211 void ViewAdaptor::deleteRow() 0212 { 0213 m_view->deleteRow(); 0214 } 0215 0216 void ViewAdaptor::insertRow() 0217 { 0218 m_view->insertRow(); 0219 } 0220 0221 void ViewAdaptor::hideRow() 0222 { 0223 m_view->hideRow(); 0224 } 0225 0226 void ViewAdaptor::showRow() 0227 { 0228 m_view->showRow(); 0229 } 0230 0231 void ViewAdaptor::hideColumn() 0232 { 0233 m_view->hideColumn(); 0234 } 0235 0236 void ViewAdaptor::showColumn() 0237 { 0238 m_view->showColumn(); 0239 } 0240 0241 void ViewAdaptor::upper() 0242 { 0243 m_view->upper(); 0244 } 0245 0246 void ViewAdaptor::lower() 0247 { 0248 m_view->lower(); 0249 } 0250 0251 void ViewAdaptor::equalizeColumn() 0252 { 0253 m_view->equalizeColumn(); 0254 } 0255 0256 void ViewAdaptor::equalizeRow() 0257 { 0258 m_view->equalizeRow(); 0259 } 0260 0261 void ViewAdaptor::clearTextSelection() 0262 { 0263 m_view->clearContents(); 0264 } 0265 0266 void ViewAdaptor::clearCommentSelection() 0267 { 0268 m_view->clearComment(); 0269 } 0270 0271 void ViewAdaptor::clearValiditySelection() 0272 { 0273 m_view->clearValidity(); 0274 } 0275 0276 void ViewAdaptor::clearConditionalSelection() 0277 { 0278 m_view->clearConditionalStyles(); 0279 } 0280 0281 void ViewAdaptor::goalSeek() 0282 { 0283 m_view->goalSeek(); 0284 } 0285 0286 void ViewAdaptor::insertFromDatabase() 0287 { 0288 m_view->insertFromDatabase(); 0289 } 0290 0291 void ViewAdaptor::insertFromTextfile() 0292 { 0293 m_view->insertFromTextfile(); 0294 } 0295 0296 void ViewAdaptor::insertFromClipboard() 0297 { 0298 m_view->insertFromClipboard(); 0299 } 0300 0301 void ViewAdaptor::textToColumns() 0302 { 0303 m_view->textToColumns(); 0304 } 0305 #endif 0306 0307 void ViewAdaptor::copyAsText() 0308 { 0309 m_view->copyAsText(); 0310 } 0311 0312 void ViewAdaptor::setSelection(const QRect& selection) 0313 { 0314 m_view->selection()->initialize(selection);//,m_view->activeSheet()); 0315 } 0316 0317 QRect ViewAdaptor::selection() 0318 { 0319 return m_view->selection()->lastRange(); 0320 } 0321 0322 #if 0 // -> cell tool 0323 void ViewAdaptor::setSelectionMoneyFormat(bool b) 0324 { 0325 m_view->moneyFormat(b); 0326 } 0327 0328 void ViewAdaptor::setSelectionPercent(bool b) 0329 { 0330 m_view->percent(b); 0331 } 0332 0333 void ViewAdaptor::setSelectionMultiRow(bool enable) 0334 { 0335 m_view->wrapText(enable); 0336 } 0337 0338 void ViewAdaptor::setSelectionSize(int size) 0339 { 0340 m_view->setSelectionFontSize(size); 0341 } 0342 0343 void ViewAdaptor::setSelectionUpper() 0344 { 0345 m_view->upper(); 0346 } 0347 0348 void ViewAdaptor::setSelectionLower() 0349 { 0350 m_view->lower(); 0351 } 0352 0353 void ViewAdaptor::setSelectionFirstLetterUpper() 0354 { 0355 m_view->firstLetterUpper(); 0356 } 0357 0358 void ViewAdaptor::setSelectionVerticalText(bool enable) 0359 { 0360 m_view->verticalText(enable); 0361 } 0362 #endif 0363 0364 void ViewAdaptor::setSelectionComment(const QString& comment) 0365 { 0366 CommentCommand* command = new CommentCommand(); 0367 command->setSheet(m_view->activeSheet()); 0368 command->setText(kundo2_i18n("Add Comment")); 0369 command->setComment(comment.trimmed()); 0370 command->add(*m_view->selection()); 0371 command->execute(); 0372 } 0373 0374 #if 0 // -> cell tool 0375 void ViewAdaptor::setSelectionAngle(int value) 0376 { 0377 m_view->setSelectionAngle(value); 0378 } 0379 #endif 0380 0381 void ViewAdaptor::setSelectionTextColor(const QColor& txtColor) 0382 { 0383 StyleCommand* command = new StyleCommand(); 0384 command->setSheet(m_view->activeSheet()); 0385 command->setText(kundo2_i18n("Change Text Color")); 0386 command->setFontColor(txtColor); 0387 command->add(*m_view->selection()); 0388 command->execute(); 0389 } 0390 0391 void ViewAdaptor::setSelectionBgColor(const QColor& bgColor) 0392 { 0393 StyleCommand* command = new StyleCommand(); 0394 command->setSheet(m_view->activeSheet()); 0395 command->setText(kundo2_i18n("Change Background Color")); 0396 command->setBackgroundColor(bgColor); 0397 command->add(*m_view->selection()); 0398 command->execute(); 0399 } 0400 0401 void ViewAdaptor::setSelectionBorderColor(const QColor& bgColor) 0402 { 0403 StyleCommand* command = new StyleCommand(); 0404 command->setSheet(m_view->activeSheet()); 0405 command->setText(kundo2_i18n("Change Background Color")); 0406 command->setBackgroundColor(bgColor); 0407 command->add(*m_view->selection()); 0408 command->execute(); 0409 } 0410 0411 #if 0 // -> cell tool 0412 void ViewAdaptor::deleteSelection() 0413 { 0414 m_view->clearAll(); 0415 } 0416 0417 void ViewAdaptor::copySelection() 0418 { 0419 m_view->copySelection(); 0420 } 0421 0422 void ViewAdaptor::cutSelection() 0423 { 0424 m_view->cutSelection(); 0425 } 0426 #endif 0427 0428 void ViewAdaptor::setLeftBorderColor(const QColor& color) 0429 { 0430 StyleCommand* command = new StyleCommand(); 0431 command->setSheet(m_view->activeSheet()); 0432 command->setText(kundo2_i18n("Change Border")); 0433 if (m_view->activeSheet()->layoutDirection() == Qt::RightToLeft) 0434 command->setRightBorderPen(QPen(color, 1, Qt::SolidLine)); 0435 else 0436 command->setLeftBorderPen(QPen(color, 1, Qt::SolidLine)); 0437 command->add(*m_view->selection()); 0438 command->execute(); 0439 } 0440 0441 void ViewAdaptor::setTopBorderColor(const QColor& color) 0442 { 0443 StyleCommand* command = new StyleCommand(); 0444 command->setSheet(m_view->activeSheet()); 0445 command->setText(kundo2_i18n("Change Border")); 0446 command->setTopBorderPen(QPen(color, 1, Qt::SolidLine)); 0447 command->add(*m_view->selection()); 0448 command->execute(); 0449 } 0450 0451 void ViewAdaptor::setRightBorderColor(const QColor& color) 0452 { 0453 StyleCommand* command = new StyleCommand(); 0454 command->setSheet(m_view->activeSheet()); 0455 command->setText(kundo2_i18n("Change Border")); 0456 if (m_view->activeSheet()->layoutDirection() == Qt::RightToLeft) 0457 command->setLeftBorderPen(QPen(color, 1, Qt::SolidLine)); 0458 else 0459 command->setRightBorderPen(QPen(color, 1, Qt::SolidLine)); 0460 command->add(*m_view->selection()); 0461 command->execute(); 0462 } 0463 0464 void ViewAdaptor::setBottomBorderColor(const QColor& color) 0465 { 0466 StyleCommand* command = new StyleCommand(); 0467 command->setSheet(m_view->activeSheet()); 0468 command->setText(kundo2_i18n("Change Border")); 0469 command->setBottomBorderPen(QPen(color, 1, Qt::SolidLine)); 0470 command->add(*m_view->selection()); 0471 command->execute(); 0472 } 0473 0474 void ViewAdaptor::setAllBorderColor(const QColor& color) 0475 { 0476 StyleCommand* command = new StyleCommand(); 0477 command->setSheet(m_view->activeSheet()); 0478 command->setText(kundo2_i18n("Change Border")); 0479 command->setTopBorderPen(QPen(color, 1, Qt::SolidLine)); 0480 command->setBottomBorderPen(QPen(color, 1, Qt::SolidLine)); 0481 command->setLeftBorderPen(QPen(color, 1, Qt::SolidLine)); 0482 command->setRightBorderPen(QPen(color, 1, Qt::SolidLine)); 0483 command->setHorizontalPen(QPen(color, 1, Qt::SolidLine)); 0484 command->setVerticalPen(QPen(color, 1, Qt::SolidLine)); 0485 command->add(*m_view->selection()); 0486 command->execute(); 0487 } 0488 0489 void ViewAdaptor::setOutlineBorderColor(const QColor& color) 0490 { 0491 StyleCommand* command = new StyleCommand(); 0492 command->setSheet(m_view->activeSheet()); 0493 command->setText(kundo2_i18n("Change Border")); 0494 command->setTopBorderPen(QPen(color, 1, Qt::SolidLine)); 0495 command->setBottomBorderPen(QPen(color, 1, Qt::SolidLine)); 0496 command->setLeftBorderPen(QPen(color, 1, Qt::SolidLine)); 0497 command->setRightBorderPen(QPen(color, 1, Qt::SolidLine)); 0498 command->add(*m_view->selection()); 0499 command->execute(); 0500 } 0501 0502 #if 0 // -> cell tool 0503 void ViewAdaptor::removeBorder() 0504 { 0505 m_view->borderRemove(); 0506 } 0507 0508 void ViewAdaptor::increaseIndent() 0509 { 0510 m_view->increaseIndent(); 0511 } 0512 0513 void ViewAdaptor::decreaseIndent() 0514 { 0515 m_view->increaseIndent(); 0516 } 0517 0518 void ViewAdaptor::increasePrecision() 0519 { 0520 m_view->increasePrecision(); 0521 } 0522 0523 void ViewAdaptor::decreasePrecision() 0524 { 0525 m_view->decreasePrecision(); 0526 } 0527 0528 void ViewAdaptor::subtotals() 0529 { 0530 m_view->subtotals(); 0531 } 0532 0533 void ViewAdaptor::sortInc() 0534 { 0535 m_view->sortInc(); 0536 } 0537 0538 void ViewAdaptor::sortDec() 0539 { 0540 m_view->sortDec(); 0541 } 0542 0543 void ViewAdaptor::layoutDlg() 0544 { 0545 m_view->layoutDlg(); 0546 } 0547 0548 0549 void ViewAdaptor::increaseFontSize() 0550 { 0551 m_view->increaseFontSize(); 0552 } 0553 0554 void ViewAdaptor::decreaseFontSize() 0555 { 0556 m_view->decreaseFontSize(); 0557 } 0558 #endif