[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/kspread
From:       Stefan Nikolaus <stefan.nikolaus () kdemail ! net>
Date:       2006-11-20 11:22:35
Message-ID: 1164021755.690059.7141.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 606408 by nikolaus:

Selection	Select All
FEATURE:	36485


 M  +82 -0     Border.cpp  
 M  +26 -0     Border.h  
 M  +8 -0      Region.cpp  
 M  +10 -2     Region.h  
 M  +3 -2      TODO  
 M  +14 -1     View.cpp  
 M  +2 -1      View.h  
 M  +3 -1      kspread.rc  


--- trunk/koffice/kspread/Border.cpp #606407:606408
@@ -1440,4 +1440,86 @@
     m_bMousePressed = false;
 }
 
+
+/****************************************************************
+ *
+ * HBorder
+ *
+ ****************************************************************/
+
+SelectAllButton::SelectAllButton( View* view  )
+    : QWidget( view )
+    , m_view( view )
+    , m_oldSelection()
+    , m_mousePressed( false )
+{
+}
+
+SelectAllButton::~SelectAllButton()
+{
+}
+
+QSize SelectAllButton::sizeHint() const
+{
+  return QSize( 40, 10 );
+}
+
+void SelectAllButton::paintEvent( QPaintEvent* event )
+{
+    // painting rectangle
+    const QRectF paintRect = m_view->doc()->viewToDocument( event->rect() );
+
+    // the painter
+    QPainter painter( this );
+    painter.scale( m_view->doc()->zoomedResolutionX(), \
m_view->doc()->zoomedResolutionY() ); +
+    painter.setClipRect( paintRect );
+
+    // if all cells are selected
+    if ( m_view->selectionInfo()->isAllSelected() )
+    {
+        // selection brush/color
+        QColor selectionColor( palette().highlight().color() );
+        selectionColor.setAlpha( 127 );
+        const QBrush selectionBrush( selectionColor );
+
+        painter.setPen( selectionColor.dark(150) );
+        painter.setBrush( selectionBrush );
+    }
+    else
+    {
+        // background brush/color
+        const QBrush backgroundBrush( palette().window() );
+        const QColor backgroundColor( backgroundBrush.color() );
+
+        painter.setPen( backgroundColor.dark(150) );
+        painter.setBrush( backgroundBrush );
+    }
+    painter.drawRect( QRectF( 0, 0, width(), height() ) );
+}
+
+void SelectAllButton::mousePressEvent( QMouseEvent* event )
+{
+    if ( event->button() == Qt::LeftButton )
+        m_mousePressed = true;
+}
+
+void SelectAllButton::mouseReleaseEvent( QMouseEvent* event )
+{
+    Q_UNUSED(event);
+    if ( !m_mousePressed )
+        return;
+    m_mousePressed = false;
+    if ( m_oldSelection.isEmpty() )
+    {
+        m_oldSelection = *m_view->selectionInfo();
+        m_view->selectionInfo()->initialize( QRect( 1, 1, KS_colMax, KS_rowMax ) );
+    }
+    else
+    {
+        m_view->selectionInfo()->initialize( m_oldSelection );
+        m_oldSelection.clear();
+    }
+}
+
 #include "Border.moc"
--- trunk/koffice/kspread/Border.h #606407:606408
@@ -170,5 +170,31 @@
     QRubberBand* m_rubberband;
 };
 
+
+
+/**
+ * The widget in the top left corner of the canvas,
+ * responsible for selecting all cells in a sheet.
+ */
+class SelectAllButton : public QWidget
+{
+    Q_OBJECT
+public:
+    SelectAllButton( View* view );
+    virtual ~SelectAllButton();
+
+    QSize sizeHint() const;
+
+protected:
+    virtual void paintEvent( QPaintEvent* event );
+    virtual void mousePressEvent( QMouseEvent* event );
+    virtual void mouseReleaseEvent( QMouseEvent* event );
+
+private:
+    View*  m_view;
+    Region m_oldSelection;
+    bool   m_mousePressed;
+};
+
 } // namespace KSpread
 #endif
--- trunk/koffice/kspread/Region.cpp #606407:606408
@@ -650,6 +650,14 @@
   return false;
 }
 
+bool Region::isAllSelected() const
+{
+    if (d->cells.count() != 1)
+        return false;
+    Q_ASSERT( d->cells.first() );
+    return d->cells.first()->isAll();
+}
+
 bool Region::contains(const QPoint& point, Sheet* sheet) const
 {
   if (d->cells.isEmpty())
--- trunk/koffice/kspread/Region.h #606407:606408
@@ -165,7 +165,7 @@
   /**
    * @param row the row to check
    *
-   * @return @c true, if the row @p row is selected. If row @p row
+   * @return @c true , if the row @p row is selected. If row @p row
    * is not given, it returns true, if at least one row is selected
    *
    * \note If you want to check more than one row for selection, use
@@ -174,11 +174,16 @@
   bool isRowSelected(uint row = 0) const;
 
   /**
-   * @return @c true,if at least one column or one row is selected
+   * @return @c true , if at least one column or one row is selected
    */
   bool isColumnOrRowSelected() const;
 
   /**
+   * @return @c true , if all cells in the sheet are selected
+   */
+  bool isAllSelected() const;
+
+  /**
    * @return a set of column numbers, for those columns, that are selected
    */
   QSet<int> columnsSelected() const;
@@ -389,6 +394,7 @@
   virtual bool isValid() const { return false; }
   virtual bool isColumn() const { return false; }
   virtual bool isRow() const { return false; }
+  virtual bool isAll() const { return false; }
 
   virtual bool contains(const QPoint&) const { return false; }
   virtual bool contains(const QRect&) const { return false; }
@@ -435,6 +441,7 @@
   virtual bool isValid() const { return (!m_point.isNull() && \
Region::isValid(m_point)); }  virtual bool isColumn() const { return false; }
   virtual bool isRow() const { return false; }
+  virtual bool isAll() const { return false; }
 
   virtual bool contains(const QPoint&) const;
   virtual bool contains(const QRect&) const;
@@ -489,6 +496,7 @@
   virtual bool isValid() const { return !m_range.isNull() && \
Region::isValid(m_range); }  virtual bool isColumn() const { return (m_range.top() == \
1 && m_range.bottom() == KS_rowMax); }  virtual bool isRow() const { return \
(m_range.left() == 1 && m_range.right() == KS_colMax); } +  virtual bool isAll() \
const { return (m_range == QRect( 1, 1, KS_colMax, KS_rowMax )); }  
   virtual bool contains(const QPoint&) const;
   virtual bool contains(const QRect&) const;
--- trunk/koffice/kspread/TODO #606407:606408
@@ -125,9 +125,10 @@
       attributes set for column/rows.
     - Fix Style::isDefault(). Use the StyleManager's default style.	----
     - Port the filters.							done
-    - Decouple validity and conditions from cells.			----
-      (think of the select all feature)
+    - Decouple validity and conditions from cells.			done
     - Fix named styles.							----
+    - Extend the Storage template to the StyleStorage level.		----
+      Garbage collection, book-keeping, ...
 
   + Speed up selection.						      1 ----
     (probably improved with Format Storage?)
--- trunk/koffice/kspread/View.cpp #606407:606408
@@ -194,6 +194,7 @@
     Canvas *canvas;
     VBorder *vBorderWidget;
     HBorder *hBorderWidget;
+    SelectAllButton* selectAllButton;
     QScrollBar *horzScrollBar;
     QScrollBar *vertScrollBar;
     KoTabBar *tabBar;
@@ -432,6 +433,7 @@
     KAction* paste;
     KAction* specialPaste;
     KAction* insertCellCopy;
+    KAction* selectAll;
     KAction* find;
     KAction* replace;
 
@@ -1022,9 +1024,11 @@
 
   actions->insertCellCopy = new KAction( KIcon( "insertcellcopy" ), i18n("Paste with \
Insertion"), ac, "insertCellCopy" );  connect(actions->insertCellCopy, \
                SIGNAL(triggered(bool)), view, SLOT( slotInsertCellCopy() ));
-
   actions->insertCellCopy->setToolTip(i18n("Inserts a cell from the clipboard into \
the spreadsheet"));  
+  actions->selectAll = KStdAction::selectAll( view, SLOT( selectAll() ), ac, \
"selectAll" ); +  actions->selectAll->setToolTip(i18n("Selects all cells in the \
current sheet")); +
   actions->find = KStdAction::find( view, SLOT(find()), ac );
   /*actions->findNext =*/ KStdAction::findNext( view, SLOT( findNext() ), ac );
   /*actions->findPrevious =*/ KStdAction::findPrev( view, SLOT( findPrevious() ), ac \
); @@ -1246,6 +1250,7 @@
   actions->paste->setEnabled( mode );
   actions->cut->setEnabled( mode );
   actions->specialPaste->setEnabled( mode );
+  actions->selectAll->setEnabled( mode );
   actions->deleteCell->setEnabled( mode );
   actions->clearText->setEnabled( mode );
   actions->clearComment->setEnabled( mode );
@@ -1716,6 +1721,8 @@
     d->vBorderWidget = new VBorder( this, d->canvas ,this );
     d->hBorderWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
     d->vBorderWidget->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding );
+    d->selectAllButton = new SelectAllButton( this );
+    d->selectAllButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
 
     d->canvas->setFocusPolicy( Qt::StrongFocus );
     QWidget::setFocusPolicy( Qt::StrongFocus );
@@ -1749,6 +1756,7 @@
     d->viewLayout->setColumnStretch( 1, 10 );
     d->viewLayout->setRowStretch( 2, 10 );
     d->viewLayout->addWidget( d->toolWidget, 0, 0, 1, 3 );
+    d->viewLayout->addWidget( d->selectAllButton, 1, 0 );
     d->viewLayout->addWidget( d->hBorderWidget, 1, 1, 1, 2 );
     d->viewLayout->addWidget( d->vBorderWidget, 2, 0 );
     d->viewLayout->addWidget( d->canvas, 2, 1 );
@@ -4003,6 +4011,11 @@
   }
 }
 
+void View::selectAll()
+{
+    selectionInfo()->initialize( QRect( 1, 1, KS_colMax, KS_rowMax ) );
+}
+
 void View::changeAngle()
 {
   AngleDialog dlg( this, "Angle", selectionInfo()->marker() );
--- trunk/koffice/kspread/View.h #606407:606408
@@ -258,7 +258,7 @@
 
     void deleteSelectedObjects();
 
-public slots:
+public Q_SLOTS:
     /**
     * refresh view when you hide/show vertical scrollbar
     */
@@ -267,6 +267,7 @@
     /**
      * Actions
      */
+    void selectAll();
     void createTemplate();
     void transformPart();
     void copySelection();
--- trunk/koffice/kspread/kspread.rc #606407:606408
@@ -1,4 +1,4 @@
-<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd" ><kpartgui name="KSpread" version="31">
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd" ><kpartgui name="KSpread" version="32">
 <MenuBar>
  <Menu name="file"><text>&amp;File</text>
   <Separator/>
@@ -20,6 +20,8 @@
         <Action name="fillLeft"/>
   </Menu>
   <Separator/>
+  <Action name="selectAll"/>
+  <Separator/>
   <Action name="edit_find"/>
   <Action name="edit_find_next"/>
   <Action name="edit_find_last"/>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic