kspread

BorderColorCommand.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright 2005-2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 // Local
00021 #include "BorderColorCommand.h"
00022 
00023 #include <kdebug.h>
00024 #include <klocale.h>
00025 
00026 #include "Cell.h"
00027 #include "CellStorage.h"
00028 #include "Sheet.h"
00029 #include "Style.h"
00030 #include "StyleStorage.h"
00031 
00032 #include <QPen>
00033 
00034 using namespace KSpread;
00035 
00036 BorderColorCommand::BorderColorCommand()
00037   : AbstractRegionCommand()
00038 {
00039     setText(i18n( "Change Border Color" ));
00040 }
00041 
00042 bool BorderColorCommand::preProcessing()
00043 {
00044     if ( m_firstrun )
00045     {
00046         QList< QPair<QRectF,SharedSubStyle> > undoData = m_sheet->styleStorage()->undoData( *this );
00047         ConstIterator endOfList = constEnd();
00048         for (ConstIterator it = constBegin(); it != endOfList; ++it)
00049         {
00050             for ( int i = 0; i < undoData.count(); ++i )
00051             {
00052                 if ( undoData[i].second->type() != Style::LeftPen ||
00053                      undoData[i].second->type() != Style::RightPen ||
00054                      undoData[i].second->type() != Style::TopPen ||
00055                      undoData[i].second->type() != Style::BottomPen ||
00056                      undoData[i].second->type() != Style::FallDiagonalPen ||
00057                      undoData[i].second->type() != Style::GoUpDiagonalPen )
00058                 {
00059                     undoData.removeAt( i-- );
00060                 }
00061             }
00062             m_undoData += undoData;
00063         }
00064     }
00065     return AbstractRegionCommand::preProcessing();
00066 }
00067 
00068 bool BorderColorCommand::mainProcessing()
00069 {
00070     if ( !m_reverse )
00071     {
00072         // change colors
00073         Style style;
00074         for ( int i = 0; i < m_undoData.count(); ++i )
00075         {
00076             style.clear();
00077             style.insertSubStyle( m_undoData[i].second );
00078             QPen pen;
00079             if ( m_undoData[i].second->type() == Style::LeftPen )
00080             {
00081                 pen = style.leftBorderPen();
00082                 pen.setColor( m_color );
00083                 style.setLeftBorderPen( pen );
00084             }
00085             if ( m_undoData[i].second->type() == Style::RightPen )
00086             {
00087                 pen = style.rightBorderPen();
00088                 pen.setColor( m_color );
00089                 style.setRightBorderPen( pen );
00090             }
00091             if ( m_undoData[i].second->type() == Style::TopPen )
00092             {
00093                 pen = style.topBorderPen();
00094                 pen.setColor( m_color );
00095                 style.setTopBorderPen( pen );
00096             }
00097             if ( m_undoData[i].second->type() == Style::BottomPen )
00098             {
00099                 pen = style.bottomBorderPen();
00100                 pen.setColor( m_color );
00101                 style.setBottomBorderPen( pen );
00102             }
00103             if ( m_undoData[i].second->type() == Style::FallDiagonalPen )
00104             {
00105                 pen = style.fallDiagonalPen();
00106                 pen.setColor( m_color );
00107                 style.setFallDiagonalPen( pen );
00108             }
00109             if ( m_undoData[i].second->type() == Style::GoUpDiagonalPen )
00110             {
00111                 pen = style.goUpDiagonalPen();
00112                 pen.setColor( m_color );
00113                 style.setGoUpDiagonalPen( pen );
00114             }
00115             m_sheet->cellStorage()->setStyle( Region(m_undoData[i].first.toRect()), style );
00116         }
00117     }
00118     else // m_reverse
00119     {
00120         for ( int i = 0; i < m_undoData.count(); ++i )
00121         {
00122             Style style;
00123             style.insertSubStyle( m_undoData[i].second );
00124             m_sheet->cellStorage()->setStyle( Region(m_undoData[i].first.toRect()), style );
00125         }
00126     }
00127     return true;
00128 }
00129 
00130 bool BorderColorCommand::postProcessing()
00131 {
00132     return true;
00133 }