File indexing completed on 2024-05-12 04:33:58

0001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-
0002 //
0003 // pageNumber.h
0004 //
0005 // Part of KVIEWSHELL - A framework for multipage text/gfx viewers
0006 //
0007 // SPDX-FileCopyrightText: 2004 Stefan Kebekus
0008 // SPDX-License-Identifier: GPL-2.0-or-later
0009 
0010 #ifndef PAGENUMBER_H
0011 #define PAGENUMBER_H
0012 
0013 #include <QGlobalStatic>
0014 
0015 /** \brief Class to represent a page number
0016 
0017 The class PageNumber is really nothing but an alias for quint16, and
0018 can be casted to and from quint16. It is used in kviewshell to remind
0019 the programmer of the convention that page numbers start at '1' (for
0020 'first page'), and that the value '0' means 'illegal page number' or
0021 'no page number'. Accordingly, the value '0' is also named
0022 PageNumber::invalidPage, and there is a trivial method isInvalid()
0023 that checks if the page number is 0.
0024 
0025 @author Stefan Kebekus <kebekus@kde.org>
0026 @version 1.0 0
0027 */
0028 
0029 class PageNumber
0030 {
0031 public:
0032     enum pageNums {
0033         invalidPage = 0 /*! Invalid page number */
0034     };
0035 
0036     /** The default constructor sets the page number to 'invalidPage' */
0037     PageNumber()
0038     {
0039         pgNum = invalidPage;
0040     }
0041 
0042     /** \brief Constructor that sets the page number
0043 
0044     @param num page number that is set initially
0045     */
0046     explicit PageNumber(quint16 num)
0047     {
0048         pgNum = num;
0049     }
0050 
0051     /** \brief this method implements typecasts from quint16 */
0052     PageNumber &operator=(const quint16 p)
0053     {
0054         pgNum = p;
0055         return *this;
0056     }
0057 
0058     /** \brief This method implements typecasts to quint16 */
0059     explicit operator quint16() const
0060     {
0061         return pgNum;
0062     }
0063 
0064     bool operator>(const PageNumber other) const
0065     {
0066         return pgNum > other.pgNum;
0067     }
0068 
0069     /** \brief Checks if the page number is invalid
0070 
0071     @returns true, if pgNum != invalidPage, i.e., does not equal 0
0072     */
0073     bool isValid() const
0074     {
0075         return (pgNum != invalidPage);
0076     }
0077 
0078 private:
0079     /** \brief Single number that represents the page number */
0080     quint16 pgNum;
0081 };
0082 
0083 #endif