File indexing completed on 2024-05-12 04:21:14

0001 
0002 /*
0003    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
0004    All rights reserved.
0005 
0006    Redistribution and use in source and binary forms, with or without
0007    modification, are permitted provided that the following conditions
0008    are met:
0009 
0010    1. Redistributions of source code must retain the above copyright
0011       notice, this list of conditions and the following disclaimer.
0012    2. Redistributions in binary form must reproduce the above copyright
0013       notice, this list of conditions and the following disclaimer in the
0014       documentation and/or other materials provided with the distribution.
0015 
0016    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0017    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0018    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0019    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0020    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0021    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0022    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0023    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0024    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0025    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0026 */
0027 
0028 
0029 #ifndef kpDocumentMetaInfoDialog_H
0030 #define kpDocumentMetaInfoDialog_H
0031 
0032 
0033 #include <QDialog>
0034 
0035 
0036 class QTableWidgetItem;
0037 
0038 class kpDocumentMetaInfo;
0039 
0040 
0041 // Dialog for editing document meta information (see kpDocumentMetaInfo).
0042 // It contains:
0043 //
0044 // 1. DPI spinboxes
0045 // 2. Offset spinboxes
0046 // 3. Text Fields
0047 //
0048 // The Text Fields widget always keeps an empty key-value row at the bottom.
0049 // If text is entered in this row, a new one is created.  This allows users
0050 // to add new rows without pressing any pushbuttons.
0051 class kpDocumentMetaInfoDialog : public QDialog
0052 {
0053 Q_OBJECT
0054 
0055 public:
0056     kpDocumentMetaInfoDialog (const kpDocumentMetaInfo *docMetaInfo,
0057                               QWidget *parent);
0058     ~kpDocumentMetaInfoDialog () override;
0059 
0060 public:
0061     bool isNoOp () const;
0062 
0063     kpDocumentMetaInfo originalMetaInfo () const;
0064 
0065     // Returns the meta information gathered from all the UI.
0066     //
0067     // If there is any invalid data in the UI (e.g. duplicate text field
0068     // keys), the returned meta information will still be valid but will not
0069     // contain the complete contents of the UI (this description is
0070     // deliberately vague so that you don't use the return value in such a
0071     // situation).  In this situation, if <errorMessage> is set, a non-empty,
0072     // translated error message will be returned through it.
0073     //
0074     // If all data in the UI is valid and <errorMessage> is set, an empty
0075     // string will be returned through it.
0076     //
0077     // If QDialog::exec() succeeded, all data in the UI was valid so the
0078     // returned meta information will be complete and correct.
0079     //
0080     // This is a slow method as it recalculates the meta information each
0081     // time it's called.
0082     kpDocumentMetaInfo metaInfo (QString *errorMessage = nullptr) const;
0083 
0084 private:
0085     void editCell (int r, int c);
0086     void fieldsUpdateVerticalHeader ();
0087 
0088     void fieldsAddEmptyRow (int atRow);
0089     void fieldsAppendEmptyRow ();
0090 
0091     bool isFieldsRowDeleteable (int row) const;
0092     void fieldsDeleteRow (int r);
0093 
0094     void enableFieldsDeleteRowButtonIfShould ();
0095 
0096 private Q_SLOTS:
0097     void setUIToOriginalMetaInfo ();
0098     void slotFieldsCurrentCellChanged (int row, int col, int oldRow, int oldCol);
0099 
0100     // Allows the user to add a row without pressing any pushbuttons:
0101     // Appends a new, blank row when text has been added to the last row.
0102     void slotFieldsItemChanged (QTableWidgetItem *item);
0103 
0104     void slotFieldsAddRowButtonClicked ();
0105     void slotFieldsDeleteRowButtonClicked ();
0106 
0107     void accept () override;
0108 
0109 private:
0110     struct kpDocumentMetaInfoDialogPrivate * const d;
0111 };
0112 
0113 
0114 #endif  // kpDocumentMetaInfoDialog_H