r17333 by fschmid - Tables: first part of implementing a gui for table and cell styles.

scribus-commit scribus-commit at lists.scribus.net
Fri Feb 24 22:11:54 UTC 2012


Author: fschmid
Date: Fri Feb 24 22:11:54 2012
New Revision: 17333

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17333
Log:
Tables: first part of implementing a gui for table and cell styles.

Modified:
    trunk/Scribus/scribus/pageitem_table.cpp
    trunk/Scribus/scribus/ui/propertiespalette_table.cpp
    trunk/Scribus/scribus/ui/propertiespalette_table.h
    trunk/Scribus/scribus/ui/propertiespalette_tablebase.ui
    trunk/Scribus/scribus/ui/spalette.cpp
    trunk/Scribus/scribus/ui/spalette.h

Modified: trunk/Scribus/scribus/pageitem_table.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17333&path=/trunk/Scribus/scribus/pageitem_table.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_table.cpp (original)
+++ trunk/Scribus/scribus/pageitem_table.cpp Fri Feb 24 22:11:54 2012
@@ -824,15 +824,19 @@
 
 void PageItem_Table::setStyle(const QString& style)
 {
+	doc()->dontResize = true;
 	m_style.setParent(style);
 	updateCells();
+	doc()->dontResize = false;
 	emit changed();
 }
 
 void PageItem_Table::unsetStyle()
 {
+	doc()->dontResize = true;
 	m_style.setParent("");
 	updateCells();
+	doc()->dontResize = false;
 	emit changed();
 }
 
@@ -843,7 +847,9 @@
 
 void PageItem_Table::handleStyleChanged()
 {
+	doc()->dontResize = true;
 	updateCells();
+	doc()->dontResize = false;
 }
 
 void PageItem_Table::applicableActions(QStringList& actionList)

Modified: trunk/Scribus/scribus/ui/propertiespalette_table.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17333&path=/trunk/Scribus/scribus/ui/propertiespalette_table.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/propertiespalette_table.cpp (original)
+++ trunk/Scribus/scribus/ui/propertiespalette_table.cpp Fri Feb 24 22:11:54 2012
@@ -32,12 +32,20 @@
 
 	addBorderLineButton->setIcon(QIcon(loadIcon("penciladd.png")));
 	removeBorderLineButton->setIcon(QIcon(loadIcon("pencilsub.png")));
+	labelTable->setBuddy(tableStyleCombo);
+	buttonClearTableStyle->setIcon(loadIcon("16/edit-clear.png"));
+	labelCells->setBuddy(cellStyleCombo);
+	buttonClearCellStyle->setIcon(loadIcon("16/edit-clear.png"));
+	connect(tableStyleCombo, SIGNAL(newStyle(const QString&)), this, SLOT(setTableStyle(const QString&)));
+	connect(cellStyleCombo, SIGNAL(newStyle(const QString&)), this, SLOT(setCellStyle(const QString&)));
 }
 
 void PropertiesPalette_Table::handleUpdateRequest(int updateFlags)
 {
 	if (updateFlags & reqColorsUpdate)
 		updateColorList();
+	tableStyleCombo->updateFormatList();
+	cellStyleCombo->updateFormatList();
 }
 
 void PropertiesPalette_Table::updateColorList()
@@ -55,20 +63,27 @@
 
 	connect(m_mainWindow, SIGNAL(UpdateRequest(int)), SLOT(handleUpdateRequest(int)));
 	connect(m_mainWindow, SIGNAL(AppModeChanged(int,int)), this, SLOT(updateFillControls()));
+	connect(m_mainWindow, SIGNAL(AppModeChanged(int,int)), this, SLOT(updateStyleControls()));
 }
 
 void PropertiesPalette_Table::setDocument(ScribusDoc *doc)
 {
 	m_doc = doc;
+	tableStyleCombo->setDoc(m_doc);
+	cellStyleCombo->setDoc(m_doc);
 }
 
 void PropertiesPalette_Table::unsetDocument()
 {
 	m_doc = 0;
+	tableStyleCombo->setDoc(m_doc);
+	cellStyleCombo->setDoc(m_doc);
 }
 
 void PropertiesPalette_Table::setItem(PageItem* item)
 {
+	tableStyleCombo->updateFormatList();
+	cellStyleCombo->updateFormatList();
 	m_item = item;
 	if (item->isTable())
 		connect(m_item->asTable(), SIGNAL(selectionChanged()), this, SLOT(handleCellSelectionChanged()));
@@ -100,6 +115,7 @@
 	sideSelector->setSelection(TableSideSelector::All);
 
 	updateFillControls();
+	updateStyleControls();
 }
 
 void PropertiesPalette_Table::handleCellSelectionChanged()
@@ -109,6 +125,72 @@
 	if (!m_item)
 		return;
 	updateFillControls();
+	updateStyleControls();
+}
+
+void PropertiesPalette_Table::displayTableStyle(const QString& name)
+{
+	bool blocked = tableStyleCombo->blockSignals(true);
+	tableStyleCombo->setFormat(name);
+	tableStyleCombo->blockSignals(blocked);
+}
+
+void PropertiesPalette_Table::displayCellStyle(const QString& name)
+{
+	bool blocked = cellStyleCombo->blockSignals(true);
+	cellStyleCombo->setFormat(name);
+	cellStyleCombo->blockSignals(blocked);
+}
+
+void PropertiesPalette_Table::updateStyleControls()
+{
+	if (m_item && m_item->isTable())
+	{
+		PageItem_Table* table = m_item->asTable();
+		tableStyleCombo->setEnabled(true);
+		cellStyleCombo->setEnabled(true);
+		buttonClearTableStyle->setEnabled(true);
+		buttonClearCellStyle->setEnabled(true);
+		// Fill in values.
+		if (m_doc->appMode != modeEditTable)
+		{
+			displayTableStyle(table->style());
+			cellStyleCombo->setEnabled(false);
+			buttonClearCellStyle->setEnabled(false);
+		}
+		else
+		{
+			displayTableStyle(table->style());
+			displayCellStyle(table->activeCell().style());
+		}
+	}
+	else
+	{
+		tableStyleCombo->setEnabled(false);
+		cellStyleCombo->setEnabled(false);
+		buttonClearTableStyle->setEnabled(false);
+		buttonClearCellStyle->setEnabled(false);
+	}
+}
+
+void PropertiesPalette_Table::setTableStyle(const QString &name)
+{
+	if (!m_item || !m_item->isTable())
+		return;
+	m_item->asTable()->setStyle(name);
+	m_item->asTable()->update();
+	displayTableStyle(name);
+}
+
+void PropertiesPalette_Table::setCellStyle(const QString &name)
+{
+	if (!m_item || !m_item->isTable())
+		return;
+	m_doc->dontResize = true;
+	m_item->asTable()->activeCell().setStyle(name);
+	m_doc->dontResize = true;
+	m_item->asTable()->update();
+	displayCellStyle(name);
 }
 
 void PropertiesPalette_Table::on_sideSelector_selectionChanged()
@@ -454,10 +536,13 @@
 
 void PropertiesPalette_Table::languageChange()
 {
+	cellStyleCombo->setToolTip( tr("Cell style of currently selected cell"));
+	tableStyleCombo->setToolTip( tr("Table style of currently selected table"));
+	labelCells->setToolTip( tr("Remove Direct Cell Formatting"));
+	labelTable->setToolTip( tr("Remove Direct Table Formatting"));
+}
+
+void PropertiesPalette_Table::unitChange()
+{
 	// Not implemented.
 }
-
-void PropertiesPalette_Table::unitChange()
-{
-	// Not implemented.
-}

Modified: trunk/Scribus/scribus/ui/propertiespalette_table.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17333&path=/trunk/Scribus/scribus/ui/propertiespalette_table.h
==============================================================================
--- trunk/Scribus/scribus/ui/propertiespalette_table.h (original)
+++ trunk/Scribus/scribus/ui/propertiespalette_table.h Fri Feb 24 22:11:54 2012
@@ -61,8 +61,11 @@
 	void unitChange();
 	/// Updates the fill controls.
 	void updateFillControls();
+	void updateStyleControls();
 
 private slots:
+	void setTableStyle(const QString& name);
+	void setCellStyle(const QString& name);
 	/// Handles selection changes in the side selector.
 	void on_sideSelector_selectionChanged();
 	/// Handles selection changes in the list of border lines.
@@ -95,6 +98,8 @@
 	};
 
 private:
+	void displayTableStyle(const QString& name);
+	void displayCellStyle(const QString& name);
 	/// Updates the list of border lines from the current border.
 	void updateBorderLineList();
 	/// Updates the current item in the list of border lines.

Modified: trunk/Scribus/scribus/ui/propertiespalette_tablebase.ui
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17333&path=/trunk/Scribus/scribus/ui/propertiespalette_tablebase.ui
==============================================================================
--- trunk/Scribus/scribus/ui/propertiespalette_tablebase.ui (original)
+++ trunk/Scribus/scribus/ui/propertiespalette_tablebase.ui Fri Feb 24 22:11:54 2012
@@ -13,7 +13,76 @@
   <property name="windowTitle">
    <string>Form</string>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout_4" stretch="1,1,0">
+  <layout class="QVBoxLayout" name="verticalLayout_2">
+   <item>
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string>Styles</string>
+     </property>
+     <layout class="QGridLayout" name="gridLayout">
+      <item row="0" column="0">
+       <widget class="QLabel" name="labelTable">
+        <property name="text">
+         <string>Table</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="TableStyleComboBox" name="tableStyleCombo">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="2">
+       <widget class="QToolButton" name="buttonClearTableStyle">
+        <property name="text">
+         <string/>
+        </property>
+        <property name="iconSize">
+         <size>
+          <width>16</width>
+          <height>16</height>
+         </size>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="labelCells">
+        <property name="text">
+         <string>Cells</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="CellStyleComboBox" name="cellStyleCombo">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="2">
+       <widget class="QToolButton" name="buttonClearCellStyle">
+        <property name="text">
+         <string/>
+        </property>
+        <property name="iconSize">
+         <size>
+          <width>16</width>
+          <height>16</height>
+         </size>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
    <item>
     <widget class="QGroupBox" name="bordersLayout">
      <property name="title">
@@ -421,6 +490,16 @@
    <extends>QDoubleSpinBox</extends>
    <header>ui/scrspinbox.h</header>
   </customwidget>
+  <customwidget>
+   <class>TableStyleComboBox</class>
+   <extends>QComboBox</extends>
+   <header>ui/spalette.h</header>
+  </customwidget>
+  <customwidget>
+   <class>CellStyleComboBox</class>
+   <extends>QComboBox</extends>
+   <header>ui/spalette.h</header>
+  </customwidget>
  </customwidgets>
  <resources/>
  <connections/>

Modified: trunk/Scribus/scribus/ui/spalette.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17333&path=/trunk/Scribus/scribus/ui/spalette.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/spalette.cpp (original)
+++ trunk/Scribus/scribus/ui/spalette.cpp Fri Feb 24 22:11:54 2012
@@ -31,9 +31,6 @@
 
 ParaStyleComboBox::ParaStyleComboBox(QWidget* parent) : QComboBox(parent)
 {
-//	setMinimumSize(QSize(10,static_cast<int>(font().pointSize()*2.5)));
-//	setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)1, 0, 0,
-//  										 sizePolicy().hasHeightForWidth() ) );
 	setEditable(false);
 	addItem( tr("No Style"));
 	currentDoc = NULL;
@@ -61,8 +58,10 @@
 		st.clear();
 		addItem( tr("No Style"));
 		for (int x = 0; x < currentDoc->paragraphStyles().count(); ++x)
+		{
 			if ( !currentDoc->paragraphStyles()[x].name().isEmpty() )
 				st.append(currentDoc->paragraphStyles()[x].name());
+		}
 		st.sort();
 		addItems(st);
 	}
@@ -87,9 +86,6 @@
 
 CharStyleComboBox::CharStyleComboBox(QWidget* parent) : QComboBox(parent)
 {
-//	setMinimumSize(QSize(10,static_cast<int>(font().pointSize()*2.5)));
-//	setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)1, 0, 0,
-//  										 sizePolicy().hasHeightForWidth() ) );
 	setEditable(false);
 	addItem( tr("No Style"));
 	currentDoc = NULL;
@@ -117,8 +113,10 @@
 		st.clear();
 		addItem( tr("No Style"));
 		for (int x = 0; x < currentDoc->charStyles().count(); ++x)
+		{
 			if ( !currentDoc->charStyles()[x].name().isEmpty() )
 				st.append(currentDoc->charStyles()[x].name());
+		}
 		st.sort();
 		addItems(st);
 	}
@@ -140,3 +138,113 @@
 		emit newStyle(currentText());
 	}
 }
+
+CellStyleComboBox::CellStyleComboBox(QWidget* parent) : QComboBox(parent)
+{
+	setEditable(false);
+	addItem( tr("No Style"));
+	currentDoc = NULL;
+	connect(this, SIGNAL(activated(int)), this, SLOT(selFormat(int)));
+}
+
+void CellStyleComboBox::setDoc(ScribusDoc *newCurrentDoc)
+{
+	currentDoc = newCurrentDoc;
+	updateFormatList();
+}
+
+void CellStyleComboBox::setFormat(QString name)
+{
+	setCurrentComboItem(this, name.isEmpty() ? tr("No Style") : name);
+}
+
+void CellStyleComboBox::updateFormatList()
+{
+	disconnect(this, SIGNAL(activated(int)), this, SLOT(selFormat(int)));
+	clear();
+	if (currentDoc != NULL)
+	{
+		QStringList st;
+		st.clear();
+		addItem( tr("No Style"));
+		for (int x = 0; x < currentDoc->cellStyles().count(); ++x)
+		{
+			if ( !currentDoc->cellStyles()[x].name().isEmpty() )
+				st.append(currentDoc->cellStyles()[x].name());
+		}
+		st.sort();
+		addItems(st);
+	}
+	QListView *tmpView = dynamic_cast<QListView*>(view());
+	int tmpWidth = tmpView->sizeHintForColumn(0);
+	if (tmpWidth > 0)
+		tmpView->setMinimumWidth(tmpWidth + 24);
+	connect(this, SIGNAL(activated(int)), this, SLOT(selFormat(int)));
+}
+
+void CellStyleComboBox::selFormat(int e)
+{
+	if (e == 0)
+	{
+		emit newStyle(QString::null);
+	}
+	else
+	{
+		emit newStyle(currentText());
+	}
+}
+
+TableStyleComboBox::TableStyleComboBox(QWidget* parent) : QComboBox(parent)
+{
+	setEditable(false);
+	addItem( tr("No Style"));
+	currentDoc = NULL;
+	connect(this, SIGNAL(activated(int)), this, SLOT(selFormat(int)));
+}
+
+void TableStyleComboBox::setDoc(ScribusDoc *newCurrentDoc)
+{
+	currentDoc = newCurrentDoc;
+	updateFormatList();
+}
+
+void TableStyleComboBox::setFormat(QString name)
+{
+	setCurrentComboItem(this, name.isEmpty() ? tr("No Style") : name);
+}
+
+void TableStyleComboBox::updateFormatList()
+{
+	disconnect(this, SIGNAL(activated(int)), this, SLOT(selFormat(int)));
+	clear();
+	if (currentDoc != NULL)
+	{
+		QStringList st;
+		st.clear();
+		addItem( tr("No Style"));
+		for (int x = 0; x < currentDoc->tableStyles().count(); ++x)
+		{
+			if ( !currentDoc->tableStyles()[x].name().isEmpty() )
+				st.append(currentDoc->tableStyles()[x].name());
+		}
+		st.sort();
+		addItems(st);
+	}
+	QListView *tmpView = dynamic_cast<QListView*>(view());
+	int tmpWidth = tmpView->sizeHintForColumn(0);
+	if (tmpWidth > 0)
+		tmpView->setMinimumWidth(tmpWidth + 24);
+	connect(this, SIGNAL(activated(int)), this, SLOT(selFormat(int)));
+}
+
+void TableStyleComboBox::selFormat(int e)
+{
+	if (e == 0)
+	{
+		emit newStyle(QString::null);
+	}
+	else
+	{
+		emit newStyle(currentText());
+	}
+}

Modified: trunk/Scribus/scribus/ui/spalette.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17333&path=/trunk/Scribus/scribus/ui/spalette.h
==============================================================================
--- trunk/Scribus/scribus/ui/spalette.h (original)
+++ trunk/Scribus/scribus/ui/spalette.h Fri Feb 24 22:11:54 2012
@@ -75,4 +75,46 @@
 	void editCharStyle();
 };
 
+class SCRIBUS_API CellStyleComboBox : public QComboBox
+{
+	Q_OBJECT
+
+public:
+	CellStyleComboBox(QWidget* parent);
+	~CellStyleComboBox() {};
+
+	ScribusDoc *currentDoc;
+
+public slots:
+	void setDoc(ScribusDoc *newCurrentDoc);
+	void setFormat(QString name);
+	void updateFormatList();
+	void selFormat(int e);
+
+signals:
+	void newStyle(const QString&);
+	void editCharStyle();
+};
+
+class SCRIBUS_API TableStyleComboBox : public QComboBox
+{
+	Q_OBJECT
+
+public:
+	TableStyleComboBox(QWidget* parent);
+	~TableStyleComboBox() {};
+
+	ScribusDoc *currentDoc;
+
+public slots:
+	void setDoc(ScribusDoc *newCurrentDoc);
+	void setFormat(QString name);
+	void updateFormatList();
+	void selFormat(int e);
+
+signals:
+	void newStyle(const QString&);
+	void editCharStyle();
+};
+
 #endif




More information about the scribus-commit mailing list