Author: jghali
Date: Sun May 27 17:59:49 2018
New Revision: 22560

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22560
Log:
#15325: columns and rows selection not working on tables

Modified:
    trunk/Scribus/scribus/canvasgesture_cellselect.cpp
    trunk/Scribus/scribus/canvasgesture_cellselect.h
    trunk/Scribus/scribus/canvasmode_edittable.cpp
    trunk/Scribus/scribus/canvasmode_edittable.h
    trunk/Scribus/scribus/pageitem_table.cpp
    trunk/Scribus/scribus/pageitem_table.h

Modified: trunk/Scribus/scribus/canvasgesture_cellselect.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=22560&path=/trunk/Scribus/scribus/canvasgesture_cellselect.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasgesture_cellselect.cpp  (original)
+++ trunk/Scribus/scribus/canvasgesture_cellselect.cpp  Sun May 27 17:59:49 2018
@@ -25,6 +25,11 @@
 #include "tablecell.h"
 #include "tableutils.h"
 #include "ui/scmwmenumanager.h"
+
+void CellSelect::activate(bool fromGesture)
+{
+       m_view->setCursor(Qt::IBeamCursor);
+}
 
 void CellSelect::deactivate(bool forGesture)
 {

Modified: trunk/Scribus/scribus/canvasgesture_cellselect.h
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=22560&path=/trunk/Scribus/scribus/canvasgesture_cellselect.h
==============================================================================
--- trunk/Scribus/scribus/canvasgesture_cellselect.h    (original)
+++ trunk/Scribus/scribus/canvasgesture_cellselect.h    Sun May 27 17:59:49 2018
@@ -36,7 +36,7 @@
        explicit CellSelect(CanvasMode* parent) : TableGesture(parent) {}
        virtual ~CellSelect() {}
 
-       virtual void activate(bool fromGesture) {}
+       virtual void activate(bool fromGesture);
        virtual void deactivate(bool forGesture);
        virtual void keyPressEvent(QKeyEvent* event);
        virtual void mousePressEvent(QMouseEvent* event);

Modified: trunk/Scribus/scribus/canvasmode_edittable.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=22560&path=/trunk/Scribus/scribus/canvasmode_edittable.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_edittable.cpp      (original)
+++ trunk/Scribus/scribus/canvasmode_edittable.cpp      Sun May 27 17:59:49 2018
@@ -147,8 +147,11 @@
        }
 
        // Pass all other keys to text frame of active cell.
-       bool repeat;
-       m_table->activeCell().textFrame()->handleModeEditKey(event, repeat);
+       if (!m_table->hasSelection())
+       {
+               bool repeat;
+               m_table->activeCell().textFrame()->handleModeEditKey(event, 
repeat);
+       }
        updateCanvas(true);
 }
 
@@ -207,6 +210,7 @@
        QPointF canvasPoint = 
m_canvas->globalToCanvas(event->globalPos()).toQPointF();
        double threshold = m_doc->guidesPrefs().grabRadius / m_canvas->scale();
        TableHandle handle = m_table->hitTest(canvasPoint, threshold);
+       TableCell cell;
 
        if (event->button() == Qt::LeftButton)
        {
@@ -214,6 +218,20 @@
                {
                        case TableHandle::RowSelect:
                                // Not implemented.
+                               m_table->clearSelection();
+                               cell = m_table->cellAt(canvasPoint);
+                               if (!cell.isValid())
+                                       break;
+                               // Deselect text in active frame.
+                               activeFrame = m_table->activeCell().textFrame();
+                               activeFrame->itemText.deselectAll();
+                               activeFrame->HasSel = false;
+                               // Select row and pre-position text cursor
+                               m_table->moveTo(cell);
+                               m_table->selectRow(cell.row());
+                               m_view->slotSetCurs(event->globalPos().x(), 
event->globalPos().y());
+                               m_lastCursorPos = -1;
+                               updateCanvas(true);
                                break;
                        case TableHandle::RowResize:
                                // Start row resize gesture.
@@ -222,6 +240,20 @@
                                break;
                        case TableHandle::ColumnSelect:
                                // Not implemented.
+                               m_table->clearSelection();
+                               cell = m_table->cellAt(canvasPoint);
+                               if (!cell.isValid())
+                                       break;
+                               // Deselect text in active frame.
+                               activeFrame = m_table->activeCell().textFrame();
+                               activeFrame->itemText.deselectAll();
+                               activeFrame->HasSel = false;
+                               // Select column and pre-position text cursor
+                               m_table->moveTo(cell);
+                               m_table->selectColumn(cell.column());
+                               m_view->slotSetCurs(event->globalPos().x(), 
event->globalPos().y());
+                               m_lastCursorPos = -1;
+                               updateCanvas(true);
                                break;
                        case TableHandle::ColumnResize:
                                // Start column resize gesture.
@@ -235,6 +267,7 @@
                                break;
                        case TableHandle::CellSelect:
                                // Move to the pressed cell and position the 
text cursor.
+                               m_table->clearSelection();
                                m_table->moveTo(m_table->cellAt(canvasPoint));
                                m_view->slotSetCurs(event->globalPos().x(), 
event->globalPos().y());
                                m_lastCursorPos = 
m_table->activeCell().textFrame()->itemText.cursorPosition();
@@ -320,7 +353,48 @@
 {
        p->save();
        commonDrawControls(p, false);
-       drawTextCursor(p);
+       if (!m_table->hasSelection())
+               drawTextCursor(p);
+       p->restore();
+
+       if (m_table->hasSelection())
+               paintCellSelection(p);
+}
+
+void CanvasMode_EditTable::paintCellSelection(QPainter* p)
+{
+       if (!m_table || !m_canvas || !p)
+               return;
+
+       p->save();
+       p->scale(m_canvas->scale(), m_canvas->scale());
+       p->translate(-m_doc->minCanvasCoordinate.x(), 
-m_doc->minCanvasCoordinate.y());
+       p->setTransform(m_table->getTransform(), true);
+       p->setRenderHint(QPainter::Antialiasing);
+       p->setPen(QPen(QColor(100, 200, 255), 3.0 / m_canvas->scale(), 
Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
+       p->setBrush(QColor(100, 200, 255, 50));
+
+       /*
+       * The code below makes selectionPath a union of the cell rectangles of 
the selected cells.
+       * Since the cell rectangles are adjacent, they must be expanded 
slightly (1.0) for the
+       * uniting to work. This may not be the fastest way to compose the path 
of the selection,
+       * but it makes for some very simple code. And the result looks good.
+       */
+
+       const QPointF offset = m_table->gridOffset();
+       QPainterPath selectionPath;
+
+       for (const TableCell& cell : m_table->selectedCells())
+       {
+               QRectF cellRect = cell.boundingRect();
+               cellRect.translate(offset);
+               cellRect.adjust(-1.0, -1.0, 1.0, 1.0);
+               QPainterPath cellPath;
+               cellPath.addRect(cellRect);
+               selectionPath = selectionPath.united(cellPath);
+       }
+
+       p->drawPath(selectionPath);
        p->restore();
 }
 

Modified: trunk/Scribus/scribus/canvasmode_edittable.h
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=22560&path=/trunk/Scribus/scribus/canvasmode_edittable.h
==============================================================================
--- trunk/Scribus/scribus/canvasmode_edittable.h        (original)
+++ trunk/Scribus/scribus/canvasmode_edittable.h        Sun May 27 17:59:49 2018
@@ -48,6 +48,12 @@
        virtual void mouseReleaseEvent(QMouseEvent* event);
        virtual void mouseDoubleClickEvent(QMouseEvent* event);
        virtual void drawControls(QPainter* p);
+
+protected:
+       /**
+       * Paints the selection of the currently edited table.
+       */
+       void paintCellSelection(QPainter* p);
 
 private slots:
        /**

Modified: trunk/Scribus/scribus/pageitem_table.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=22560&path=/trunk/Scribus/scribus/pageitem_table.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_table.cpp    (original)
+++ trunk/Scribus/scribus/pageitem_table.cpp    Sun May 27 17:59:49 2018
@@ -766,6 +766,20 @@
                for (int col = leftCol; col <= rightCol; ++col)
                        selectCell(row, col);
        emit selectionChanged();
+}
+
+void PageItem_Table::selectColumn(int column)
+{
+       if (!validCell(0, column))
+               return;
+       selectCells(0, column, rows() - 1, column);
+}
+
+void PageItem_Table::selectRow(int row)
+{
+       if (!validCell(row, 0))
+               return;
+       selectCells(row, 0, row, columns() - 1);
 }
 
 void PageItem_Table::clearSelection()

Modified: trunk/Scribus/scribus/pageitem_table.h
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=22560&path=/trunk/Scribus/scribus/pageitem_table.h
==============================================================================
--- trunk/Scribus/scribus/pageitem_table.h      (original)
+++ trunk/Scribus/scribus/pageitem_table.h      Sun May 27 17:59:49 2018
@@ -319,9 +319,28 @@
        void selectCells(int startRow, int startColumn, int endRow, int 
endColumn);
 
        /**
+        * Adds the cells in specified column to the selection.
+        *
+        * If specified column is outside the table, this function does nothing.
+        */
+       void selectColumn(int column);
+
+       /**
+       * Adds the cells in specified row to the selection.
+       *
+       * If specified row is outside the table, this function does nothing.
+       */
+       void selectRow(int row);
+
+       /**
         * Clears the cell selection.
         */
        void clearSelection();
+
+       /**
+        * Test if item has an active cell selection
+        */
+       bool hasSelection() const { return m_selection.count() > 0; }
 
        /**
         * Returns the cell at @a row, @a column.


_______________________________________________
scribus-commit mailing list
[email protected]
http://lists.scribus.net/mailman/listinfo/scribus-commit

Reply via email to