File indexing completed on 2024-05-12 16:41:07
0001 /******************************************************************************************** 0002 Copyright (C) 2008 by Mathias Soeken (msoeken@informatik.uni-bremen.de) 0003 (C) 2005-2006 by Holger Danielsson (holger.danielsson@t-online.de) 0004 (C) 2012 by Michel Ludwig (michel.ludwig@kdemail.net) 0005 ********************************************************************************************/ 0006 0007 /*************************************************************************** 0008 * * 0009 * This program is free software; you can redistribute it and/or modify * 0010 * it under the terms of the GNU General Public License as published by * 0011 * the Free Software Foundation; either version 2 of the License, or * 0012 * (at your option) any later version. * 0013 * * 0014 ***************************************************************************/ 0015 0016 #include "tabularcell.h" 0017 0018 #include "tabularheaderitem.h" 0019 #include "tabularproperties.h" 0020 0021 namespace KileDialog { 0022 0023 //BEGIN TabularCell 0024 TabularCell::TabularCell() 0025 : QTableWidgetItem(), 0026 m_Border(None) 0027 { 0028 } 0029 0030 TabularCell::TabularCell(const QString &text) 0031 : QTableWidgetItem(text), 0032 m_Border(None) 0033 { 0034 } 0035 0036 void TabularCell::setBorder(int border) 0037 { 0038 m_Border = border; 0039 tableWidget()->update(); 0040 } 0041 0042 int TabularCell::border() const 0043 { 0044 return m_Border; 0045 } 0046 0047 QString TabularCell::toLaTeX( TabularProperties &properties ) const 0048 { 0049 QString prefix; 0050 QString suffix; 0051 0052 int alignment = textAlignment() & ~Qt::AlignVCenter; 0053 TabularHeaderItem *headerItem = static_cast<TabularHeaderItem*>(tableWidget()->horizontalHeaderItem(column())); 0054 0055 QString colorCommand; 0056 if(background().style() != Qt::NoBrush 0057 && !properties.rowColor(row()).isValid()) { 0058 colorCommand = ">{\\columncolor{" + properties.colorName(background().color()) + "}}"; 0059 } 0060 0061 QString leftBorder, rightBorder; 0062 // First col border always needs to be set 0063 if(column() == 0) { 0064 if(border() & TabularCell::Left) { 0065 leftBorder = '|'; 0066 } 0067 } 0068 // Does the cell have a right border? 0069 if(border() & TabularCell::Right) { 0070 rightBorder = '|'; 0071 } 0072 0073 bool adjustBorder = false; 0074 // If 1st col has no left border, but the cell should have one, set it manually 0075 if(column() == 0 && !properties.hasLeftBorder() && 0076 (border() & TabularCell::Left)) { 0077 adjustBorder = true; 0078 } 0079 // Do we have to set the right border manually? 0080 if(!properties.hasBorderBesideColumn(column()) && 0081 (border() & TabularCell::Right)) { 0082 adjustBorder = true; 0083 } 0084 0085 int columnSpan = tableWidget()->columnSpan(row(), column()); 0086 0087 if(headerItem->alignment() != alignment || !colorCommand.isEmpty() || 0088 adjustBorder || columnSpan > 1 ) { 0089 0090 switch(alignment) { 0091 case Qt::AlignHCenter: 0092 properties.setUseMultiColumn(); 0093 prefix += "\\mc{" + QString::number(columnSpan) + "}{" + 0094 leftBorder + colorCommand + 'c' + rightBorder + "}{"; 0095 suffix = '}' + suffix; 0096 break; 0097 0098 case Qt::AlignRight: 0099 properties.setUseMultiColumn(); 0100 prefix += "\\mc{" + QString::number(columnSpan) + "}{" + 0101 leftBorder + colorCommand + 'r' + rightBorder + "}{"; 0102 suffix = '}' + suffix; 0103 break; 0104 default: // This handles Qt::AlignLeft, 0105 // alignP, alignM, alignB and alignX (they get thrown away here) 0106 properties.setUseMultiColumn(); 0107 prefix += "\\mc{" + QString::number(columnSpan) + "}{" + 0108 leftBorder + colorCommand + 'l' + rightBorder + "}{"; 0109 suffix = '}' + suffix; 0110 break; 0111 }; 0112 } 0113 0114 /* format */ 0115 if (font().bold()) { 0116 prefix += "\\textbf{"; 0117 suffix = '}' + suffix; 0118 } 0119 if (font().italic()) { 0120 prefix += "\\textit{"; 0121 suffix = '}' + suffix; 0122 } 0123 0124 /* prefix */ 0125 if (font().underline()) { 0126 prefix += "\\underline{"; 0127 suffix = '}' + suffix; 0128 } 0129 0130 /* foreground color */ 0131 if(foreground().style() != Qt::NoBrush) { 0132 prefix += "\\textcolor{" + properties.colorName(foreground().color()) + "}{"; 0133 suffix = '}' + suffix; 0134 } 0135 0136 /* content */ 0137 QString content = ""; 0138 QString incontent = text().trimmed(); 0139 if(incontent.isEmpty()) { 0140 incontent = properties.bullet(); 0141 } 0142 content += prefix + incontent + suffix; 0143 return content; 0144 } 0145 //END 0146 0147 }