kprefsdialog.h 22.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
  This file is part of libkdepim.

  Copyright (c) 2001-2003 Cornelius Schumacher <schumacher@kde.org>
  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
  Copyright (C) 2005,2008,2011 Allen Winter <winter@kde.org>

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Library General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Library General Public License for more details.

  You should have received a copy of the GNU Library General Public License
  along with this library; see the file COPYING.LIB.  If not, write to
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  Boston, MA 02110-1301, USA.
*/
#ifndef KDEPIM_KPREFSDIALOG_H
#define KDEPIM_KPREFSDIALOG_H

#include "kdepim_export.h"

#include <KConfigSkeleton>
29
#include <KFile>
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <KLineEdit>
#include <KPageDialog>
#include <KCModule>

#include <QVariantList>

class KColorButton;
class KComboBox;
class KDateComboBox;
class KTimeComboBox;
class KUrlRequester;

class QCheckBox;
class QLabel;
class QSpinBox;
class QTimeEdit;
class QButtonGroup;
class QGroupBox;

Laurent Montel's avatar
Laurent Montel committed
49
namespace KPIM {
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
/**
  @short Base class for GUI control elements used by @ref KPrefsDialog.
  @author Cornelius Schumacher
  @see KPrefsDialog

  This class provides the interface for the GUI control elements used by
  KPrefsDialog. The control element consists of a set of widgets for handling
  a certain type of configuration information.
*/
class KDEPIM_EXPORT KPrefsWid : public QObject
{
    Q_OBJECT
public:
    /**
      This function is called to read value of the setting from the
      stored configuration and display it in the widget.
    */
    virtual void readConfig() = 0;
    /**
      This function is called to write the current setting of the widget to the
      stored configuration.
    */
    virtual void writeConfig() = 0;

    /**
      Return a list of widgets used by this control element.
    */
    virtual QList<QWidget *> widgets() const;

Q_SIGNALS:
    /**
      Emitted when widget value has changed.
    */
    void changed();
};

/**
  @short Widgets for bool settings in @ref KPrefsDialog.

  This class provides a control element for configuring bool values. It is meant
  to be used by KPrefsDialog. The user is responsible for the layout management.
*/
class KDEPIM_EXPORT KPrefsWidBool : public KPrefsWid
{
    Q_OBJECT
public:
    /**
      Create a bool value control element consisting of a QCheckbox.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
102
    explicit KPrefsWidBool(KConfigSkeleton::ItemBool *item, QWidget *parent = nullptr);
103 104 105 106 107 108

    /**
      Return the QCheckbox used by this control element.
    */
    QCheckBox *checkBox();

109 110
    void readConfig() override;
    void writeConfig() override;
111

112
    QList<QWidget *> widgets() const override;
113 114

private:
Laurent Montel's avatar
Laurent Montel committed
115
    KConfigSkeleton::ItemBool *mItem = nullptr;
116

Laurent Montel's avatar
Laurent Montel committed
117
    QCheckBox *mCheck = nullptr;
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
};

/**
  @short Widgets for int settings in @ref KPrefsDialog.

  This class provides a control element for configuring integer values. It is
  meant to be used by KPrefsDialog. The user is responsible for the layout
  management.
*/
class KDEPIM_EXPORT KPrefsWidInt : public KPrefsWid
{
    Q_OBJECT
public:
    /**
      Create a integer value control element consisting of a label and a
      spinbox.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
138
    explicit KPrefsWidInt(KConfigSkeleton::ItemInt *item, QWidget *parent = nullptr);
139 140 141 142 143 144 145 146 147 148 149

    /**
      Return QLabel used by this control element.
    */
    QLabel *label() const;

    /**
      Return the QSpinBox used by this control element.
    */
    QSpinBox *spinBox();

150 151
    void readConfig() override;
    void writeConfig() override;
152

153
    QList<QWidget *> widgets() const override;
154 155

private:
Laurent Montel's avatar
Laurent Montel committed
156
    KConfigSkeleton::ItemInt *mItem = nullptr;
157

Laurent Montel's avatar
Laurent Montel committed
158 159
    QLabel *mLabel = nullptr;
    QSpinBox *mSpin = nullptr;
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
};

/**
  @short Widgets for time settings in @ref KPrefsDialog.

  This class provides a control element for configuring time values. It is
  meant to be used by KPrefsDialog. The user is responsible for the layout
  management.
*/
class KDEPIM_EXPORT KPrefsWidTime : public KPrefsWid
{
    Q_OBJECT
public:
    /**
      Create a time value control element consisting of a label and a spinbox.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
179
    explicit KPrefsWidTime(KConfigSkeleton::ItemDateTime *item, QWidget *parent = nullptr);
180 181 182 183 184 185 186 187 188 189 190

    /**
      Return QLabel used by this widget.
    */
    QLabel *label();

    /**
      Return KTimeComboBox used by this widget.
    */
    KTimeComboBox *timeEdit();

191 192
    void readConfig() override;
    void writeConfig() override;
193 194

private:
Laurent Montel's avatar
Laurent Montel committed
195
    KConfigSkeleton::ItemDateTime *mItem = nullptr;
196

Laurent Montel's avatar
Laurent Montel committed
197 198
    QLabel *mLabel = nullptr;
    KTimeComboBox *mTimeEdit = nullptr;
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
};

/**
  @short Widgets for duration settings in @ref KPrefsDialog.

  This class provides a control element for configuring duration values. It is
  meant to be used by KPrefsDialog. The user is responsible for the layout
  management.
*/
class KDEPIM_EXPORT KPrefsWidDuration : public KPrefsWid
{
    Q_OBJECT
public:
    /**
      Create a duration value control element consisting of a label and a
      spinbox.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param format  display format. default is "hh:mm:ss"
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
220
    explicit KPrefsWidDuration(KConfigSkeleton::ItemDateTime *item, const QString &format, QWidget *parent = nullptr);
221 222 223 224 225 226 227 228 229 230

    /**
      Return QLabel used by this widget.
    */
    QLabel *label();
    /**
      Return QSpinBox used by this widget.
    */
    QTimeEdit *timeEdit();

231 232
    void readConfig() override;
    void writeConfig() override;
233 234

private:
Laurent Montel's avatar
Laurent Montel committed
235
    KConfigSkeleton::ItemDateTime *mItem = nullptr;
236

Laurent Montel's avatar
Laurent Montel committed
237 238
    QLabel *mLabel = nullptr;
    QTimeEdit *mTimeEdit = nullptr;
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
};

/**
  @short Widgets for time settings in @ref KPrefsDialog.

  This class provides a control element for configuring date values. It is
  meant to be used by KPrefsDialog. The user is responsible for the layout
  management.
*/
class KDEPIM_EXPORT KPrefsWidDate : public KPrefsWid
{
    Q_OBJECT
public:
    /**
      Create a time value control element consisting of a label and a date box.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
258
    explicit KPrefsWidDate(KConfigSkeleton::ItemDateTime *item, QWidget *parent = nullptr);
259 260 261 262 263 264 265 266 267 268 269

    /**
      Return QLabel used by this widget.
    */
    QLabel *label();

    /**
      Return KDateComboBox used by this widget.
    */
    KDateComboBox *dateEdit();

270 271
    void readConfig() override;
    void writeConfig() override;
272 273

private:
Laurent Montel's avatar
Laurent Montel committed
274
    KConfigSkeleton::ItemDateTime *mItem = nullptr;
275

Laurent Montel's avatar
Laurent Montel committed
276 277
    QLabel *mLabel = nullptr;
    KDateComboBox *mDateEdit = nullptr;
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
};

/**
  @short Widgets for color settings in @ref KPrefsDialog.

  This class provides a control element for configuring color values. It is
  meant to be used by KPrefsDialog. The user is responsible for the layout
  management.
*/
class KDEPIM_EXPORT KPrefsWidColor : public KPrefsWid
{
    Q_OBJECT
public:
    /**
      Create a color value control element consisting of a test field and a
      button for opening a color dialog.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
298
    explicit KPrefsWidColor(KConfigSkeleton::ItemColor *item, QWidget *parent = nullptr);
299 300 301 302

    /**
      Destruct color setting widget.
    */
Laurent Montel's avatar
Laurent Montel committed
303
    ~KPrefsWidColor() override;
304 305 306 307 308 309 310 311 312 313

    /**
      Return QLabel for the button
    */
    QLabel *label();
    /**
      Return button opening the color dialog.
    */
    KColorButton *button();

314 315
    void readConfig() override;
    void writeConfig() override;
316 317

private:
Laurent Montel's avatar
Laurent Montel committed
318
    KConfigSkeleton::ItemColor *mItem = nullptr;
319

Laurent Montel's avatar
Laurent Montel committed
320 321
    QLabel *mLabel = nullptr;
    KColorButton *mButton = nullptr;
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
};

/**
  @short Widgets for font settings in @ref KPrefsDialog.

  This class provides a control element for configuring font values. It is meant
  to be used by KPrefsDialog. The user is responsible for the layout management.
*/
class KDEPIM_EXPORT KPrefsWidFont : public KPrefsWid
{
    Q_OBJECT
public:
    /**
      Create a font value control element consisting of a test field and a
      button for opening a font dialog.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
      @param sampleText Sample text for previewing the selected font.
    */
Laurent Montel's avatar
Laurent Montel committed
342
    explicit KPrefsWidFont(KConfigSkeleton::ItemFont *item, QWidget *parent = nullptr, const QString &sampleText = QString());
343 344 345
    /**
      Destruct font setting widget.
    */
Laurent Montel's avatar
Laurent Montel committed
346
    ~KPrefsWidFont() override;
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362

    /**
      Return QLabel.
    */
    QLabel *label();

    /**
      Return QFrame used as preview field.
    */
    QFrame *preview();

    /**
      Return button opening the font dialog.
    */
    QPushButton *button();

363 364
    void readConfig() override;
    void writeConfig() override;
365 366 367 368 369

protected Q_SLOTS:
    void selectFont();

private:
Laurent Montel's avatar
Laurent Montel committed
370
    KConfigSkeleton::ItemFont *mItem = nullptr;
371

Laurent Montel's avatar
Laurent Montel committed
372 373 374
    QLabel *mLabel = nullptr;
    QLabel *mPreview = nullptr;
    QPushButton *mButton = nullptr;
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
};

/**
  @short Widgets for settings represented by a group of radio buttons in
  @ref KPrefsDialog.

  This class provides a control element for configuring selections. It is meant
  to be used by KPrefsDialog. The user is responsible for the layout management.

  The setting is interpreted as an int value, corresponding to the position of
  the radio button. The position of the button is defined by the sequence of
  @ref addRadio() calls, starting with 0.
*/
class KDEPIM_EXPORT KPrefsWidRadios : public KPrefsWid
{
    Q_OBJECT
public:
    /**
      Create a control element for selection of an option. It consists of a box
      with several radio buttons.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
399
    explicit KPrefsWidRadios(KConfigSkeleton::ItemEnum *item, QWidget *parent = nullptr);
Laurent Montel's avatar
Laurent Montel committed
400
    ~KPrefsWidRadios() override;
401 402 403 404 405 406 407 408 409

    /**
      Add a radio button.

      @param value The enum value represented by this radio button.
      @param text Text of the button.
      @param toolTip ToolTip help for the button.
      @param whatsThis What's This help for the button.
    */
Laurent Montel's avatar
Laurent Montel committed
410
    void addRadio(int value, const QString &text, const QString &toolTip = QString(), const QString &whatsThis = QString());
411 412 413 414 415 416

    /**
      Return the box widget used by this widget.
    */
    QGroupBox *groupBox() const;

417 418
    void readConfig() override;
    void writeConfig() override;
419

420
    QList<QWidget *> widgets() const override;
421 422

private:
Laurent Montel's avatar
Laurent Montel committed
423
    KConfigSkeleton::ItemEnum *mItem = nullptr;
424

Laurent Montel's avatar
Laurent Montel committed
425 426
    QGroupBox *mBox = nullptr;
    QButtonGroup *mGroup = nullptr;
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
};

/**
  @short Widgets for settings represented by a combo box in
  @ref KPrefsDialog.

  This class provides a control element for configuring selections. It is meant
  to be used by KPrefsDialog. The user is responsible for the layout management.

  The setting is interpreted as an int value, corresponding to the index in
  the combo box.
*/
class KDEPIM_EXPORT KPrefsWidCombo : public KPrefsWid
{
    Q_OBJECT
public:
    /**
      Create a control element for selection of an option. It consists of a
      combo box.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
    explicit KPrefsWidCombo(KConfigSkeleton::ItemEnum *item, QWidget *parent);
Laurent Montel's avatar
Laurent Montel committed
451
    ~KPrefsWidCombo() override;
452

453 454
    void readConfig() override;
    void writeConfig() override;
455 456 457

    KComboBox *comboBox();

458
    QList<QWidget *> widgets() const override;
459 460 461 462 463 464
    /**
      Return QLabel used by this control element.
    */
    QLabel *label() const;

private:
Laurent Montel's avatar
Laurent Montel committed
465 466 467
    KConfigSkeleton::ItemEnum *mItem = nullptr;
    KComboBox *mCombo = nullptr;
    QLabel *mLabel = nullptr;
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
};

/**
  @short Widgets for string settings in @ref KPrefsDialog.

  This class provides a control element for configuring string values. It is
  meant to be used by KPrefsDialog. The user is responsible for the layout
  management.
*/
class KDEPIM_EXPORT KPrefsWidString : public KPrefsWid
{
    Q_OBJECT
public:
    /**
      Create a string value control element consisting of a test label and a
      line edit.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
      @param echomode  Describes how a line edit should display its contents.
    */
Laurent Montel's avatar
Laurent Montel committed
489
    explicit KPrefsWidString(KConfigSkeleton::ItemString *item, QWidget *parent = nullptr, KLineEdit::EchoMode echomode = KLineEdit::Normal);
490 491 492
    /**
      Destructor.
    */
Laurent Montel's avatar
Laurent Montel committed
493
    ~KPrefsWidString() override;
494 495 496 497 498 499 500 501 502 503

    /**
      Return QLabel used by this widget.
    */
    QLabel *label();
    /**
      Return KLineEdit used by this widget.
    */
    KLineEdit *lineEdit();

504 505
    void readConfig() override;
    void writeConfig() override;
506

507
    QList<QWidget *> widgets() const override;
508 509

private:
Laurent Montel's avatar
Laurent Montel committed
510
    KConfigSkeleton::ItemString *mItem = nullptr;
511

Laurent Montel's avatar
Laurent Montel committed
512 513
    QLabel *mLabel = nullptr;
    KLineEdit *mEdit = nullptr;
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
};

/**
  @short Widgets for string settings in @ref KPrefsDialog.

  This class provides a control element for configuring string values. It is
  meant to be used by KPrefsDialog. The user is responsible for the layout
  management.
*/
class KDEPIM_EXPORT KPrefsWidPath : public KPrefsWid
{
    Q_OBJECT
public:
    /**
      Create a string value control element consisting of a test label and a
      line edit.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
      @param filter URLRequester filter
      @param mode  Describes how a line edit should display its contents.
    */
Laurent Montel's avatar
Laurent Montel committed
536
    explicit KPrefsWidPath(KConfigSkeleton::ItemPath *item, QWidget *parent = nullptr, const QString &filter = QString(), KFile::Modes = KFile::File);
537 538 539 540

    /**
      Destructor.
    */
Laurent Montel's avatar
Laurent Montel committed
541
    ~KPrefsWidPath() override;
542 543 544 545 546 547 548 549 550 551 552

    /**
      Return QLabel used by this widget.
    */
    QLabel *label();

    /**
      Return KUrlRequester used by this widget.
    */
    KUrlRequester *urlRequester();

553 554
    void readConfig() override;
    void writeConfig() override;
555

556
    QList<QWidget *> widgets() const override;
557 558

private:
Laurent Montel's avatar
Laurent Montel committed
559
    KConfigSkeleton::ItemPath *mItem = nullptr;
560

Laurent Montel's avatar
Laurent Montel committed
561 562
    QLabel *mLabel = nullptr;
    KUrlRequester *mURLRequester = nullptr;
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
};

/**
  @short Class for managing KPrefsWid objects.

  This class manages standard configuration widgets provided bz the KPrefsWid
  subclasses. It handles creation, loading, saving and default values in a
  transparent way. The user has to add the widgets by the corresponding addWid
  functions and KPrefsWidManager handles the rest automatically.
*/
class KDEPIM_EXPORT KPrefsWidManager
{
public:
    /**
      Create a KPrefsWidManager object for a KPrefs object.

      @param prefs  KPrefs object used to access te configuration.
    */
    explicit KPrefsWidManager(KConfigSkeleton *prefs);

    /**
      Destructor.
    */
    virtual ~KPrefsWidManager();

    KConfigSkeleton *prefs() const
    {
        return mPrefs;
    }

    /**
      Register a custom KPrefsWid object.
    */
    virtual void addWid(KPrefsWid *);

    /**
      Register a @ref KPrefsWidBool object.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
604
    KPrefsWidBool *addWidBool(KConfigSkeleton::ItemBool *item, QWidget *parent = nullptr);
605 606 607 608 609 610 611

    /**
      Register a @ref KPrefsWidInt object.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
612
    KPrefsWidInt *addWidInt(KConfigSkeleton::ItemInt *item, QWidget *parent = nullptr);
613 614 615 616 617 618 619

    /**
      Register a @ref KPrefsWidDate object.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
620
    KPrefsWidDate *addWidDate(KConfigSkeleton::ItemDateTime *item, QWidget *parent = nullptr);
621 622 623 624 625 626 627

    /**
      Register a @ref KPrefsWidTime object.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
628
    KPrefsWidTime *addWidTime(KConfigSkeleton::ItemDateTime *item, QWidget *parent = nullptr);
629 630 631 632 633 634 635 636

    /**
      Register a @ref KPrefsWidDuration object.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param format  display format. default is "hh:mm:ss"
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
637
    KPrefsWidDuration *addWidDuration(KConfigSkeleton::ItemDateTime *item, const QString &format, QWidget *parent = nullptr);
638 639 640 641 642 643 644

    /**
      Register a @ref KPrefsWidColor object.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
645
    KPrefsWidColor *addWidColor(KConfigSkeleton::ItemColor *item, QWidget *parent = nullptr);
646 647 648 649 650 651 652 653

    /**
      Register a @ref KPrefsWidRadios object. The choices represented by the
      given item object are automatically added as radio buttons.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
654
    KPrefsWidRadios *addWidRadios(KConfigSkeleton::ItemEnum *item, QWidget *parent = nullptr);
655 656 657 658 659 660 661 662

    /**
      Register a @ref KPrefsWidCombo object. The choices represented by the
      given item object are automatically added to the combo box.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
663
    KPrefsWidCombo *addWidCombo(KConfigSkeleton::ItemEnum *item, QWidget *parent = nullptr);
664 665 666 667 668 669 670

    /**
      Register a @ref KPrefsWidString object.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
671
    KPrefsWidString *addWidString(KConfigSkeleton::ItemString *item, QWidget *parent = nullptr);
672 673 674 675 676 677 678 679 680

    /**
      Register a path @ref KPrefsWidPath object.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
      @param filter URLRequester filter
      @param mode URLRequester mode
    */
Laurent Montel's avatar
Laurent Montel committed
681
    KPrefsWidPath *addWidPath(KConfigSkeleton::ItemPath *item, QWidget *parent = nullptr, const QString &filter = QString(), KFile::Modes mode = KFile::File);
682 683 684 685 686 687 688

    /**
      Register a password @ref KPrefsWidString object, with echomode set to KLineEdit::Password.

      @param item    The KConfigSkeletonItem representing the preferences entry.
      @param parent  Parent widget.
    */
Laurent Montel's avatar
Laurent Montel committed
689
    KPrefsWidString *addWidPassword(KConfigSkeleton::ItemString *item, QWidget *parent = nullptr);
690 691 692 693 694 695 696 697 698

    /**
      Register a @ref KPrefsWidFont object.

      @param item       The KConfigSkeletonItem representing the preferences
                        entry.
      @param parent     Parent widget.
      @param sampleText Sample text for previewing the selected font.
    */
Laurent Montel's avatar
Laurent Montel committed
699
    KPrefsWidFont *addWidFont(KConfigSkeleton::ItemFont *item, QWidget *parent = nullptr, const QString &sampleText = QString());
700 701 702 703 704 705 706 707 708 709 710

    /** Set all widgets to default values. */
    void setWidDefaults();

    /** Read preferences from config file. */
    void readWidConfig();

    /** Write preferences to config file. */
    void writeWidConfig();

private:
Laurent Montel's avatar
Laurent Montel committed
711
    KConfigSkeleton *mPrefs = nullptr;
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739

    QList<KPrefsWid *> mPrefsWids;
};

/**
  @short Base class for a preferences dialog.

  This class provides the framework for a preferences dialog. You have to
  subclass it and add the code to create the actual configuration widgets and
  do the layout management.

  KPrefsDialog provides functions to add subclasses of @ref KPrefsWid via
  KPrefsWidManager. For these widgets the reading, writing and setting to
  default values is handled automatically. Custom widgets have to be handled in
  the functions @ref usrReadConfig() and @ref usrWriteConfig().
*/
class KDEPIM_EXPORT KPrefsDialog : public KPageDialog, public KPrefsWidManager
{
    Q_OBJECT
public:
    /**
      Create a KPrefsDialog for a KPrefs object.

      @param prefs  KPrefs object used to access te configuration.
      @param parent Parent widget.
      @param name   Widget name.
      @param modal  true, if dialog has to be modal, false for non-modal.
    */
Laurent Montel's avatar
Laurent Montel committed
740
    explicit KPrefsDialog(KConfigSkeleton *prefs, QWidget *parent = nullptr, bool modal = false);
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774

    /**
      Destructor.
    */
    virtual ~KPrefsDialog();

    void autoCreate();

public Q_SLOTS:
    /** Set all widgets to default values. */
    void setDefaults();

    /** Read preferences from config file. */
    void readConfig();

    /** Write preferences to config file. */
    void writeConfig();

Q_SIGNALS:
    /** Emitted when the a changed configuration has been stored. */
    void configChanged();

protected Q_SLOTS:
    /** Apply changes to preferences */
    void slotApply();

    /** Accept changes to preferences and close dialog */
    void slotOk();

    /** Set preferences to default values */
    void slotDefault();

protected:
    /** Implement this to read custom configuration widgets. */
Laurent Montel's avatar
Laurent Montel committed
775 776 777 778
    virtual void usrReadConfig()
    {
    }

779
    /** Implement this to write custom configuration widgets. */
Laurent Montel's avatar
Laurent Montel committed
780 781 782
    virtual void usrWriteConfig()
    {
    }
783 784 785 786 787 788
};

class KDEPIM_EXPORT KPrefsModule : public KCModule, public KPrefsWidManager
{
    Q_OBJECT
public:
Laurent Montel's avatar
Laurent Montel committed
789
    KPrefsModule(KConfigSkeleton *, QWidget *parent = nullptr, const QVariantList &args = QVariantList());
790

791
    void addWid(KPrefsWid *) override;
792

793 794 795
    void load() override;
    void save() override;
    void defaults() override;
796 797 798 799 800 801

public Q_SLOTS:
    void slotWidChanged();

protected:
    /** Implement this to read custom configuration widgets. */
Laurent Montel's avatar
Laurent Montel committed
802 803 804 805
    virtual void usrReadConfig()
    {
    }

806
    /** Implement this to write custom configuration widgets. */
Laurent Montel's avatar
Laurent Montel committed
807 808 809
    virtual void usrWriteConfig()
    {
    }
810 811 812 813
};
}

#endif