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

List:       kde-core-devel
Subject:    Re: DialogCore / AboutCore classes
From:       Espen Sand <espen.sand () neo ! no>
Date:       1999-09-02 7:19:19
[Download RAW message or body]

Hello, I have some explanations and code below

On tor, 02 sep 1999, Mirko Sucker wrote:
>
>> 1. Perhaps most important. I use no resizeEvent() event handler. Everything
>> is taken care of by the Qt layout mechanism. This makes the dialog code *much*
>> simpler to maintain (at least my experience :-). I have reimplemented the
>> show() method where I basically only do:
>> setGeometry( x(), y(), minimumSize().width(),minimumSize().height() );
>> QDialog::show();
>> Thats the only place I set the size of anything in the CDialogCore.
>
>Hello Espen,
>this is a kind of misunderstanding.
>When using DialogBase, the user does not have to take care of any resize handling at
>all. The only thing that has to be done by the user is to set the minimum size for the
>main widget. As DialogBase places some frames around it, it need to handle its own
>resizing - thats all. So, if you need to set up your dialog, you only take care for
>your own widgets. This is the same if you derive DialogBase or use it directly as
>I mentioned in the last mail.
>
What I meant was not the "end-user" prespective. I was refering to what will
happen the day the DialogBase layout is to be changed a little bit, and the guy
that does this is not you. IMHO it takes longer time and is more complicated to
get things correct when resizing code is done "manually" instead of using
the Qt layout mechanism. I have included the entire constructor the the end of
the mail (it is not that big :). NOTE: I do not resize anything outside this
constructor.

>> 2. I needed more Action buttons (other than Apply,Ok and Cancel) at the same
>> time So I added Help,Default and Close, as well as the user definable buttons.
>> In all, eight button can be used in a dialog at the same time.
>
>OK, this is not a problem. In DialogBase, the buttons are simply the ones that have
>been used until now. But be aware - user buttons usually do NOT have the same
>synoptical meaning as the three buttons OK, Apply and Cancel. Regarding this, you need
>to place them differently to create a comprehensable user interface.
>
Have look on how I do that below.

>
>> 3. The user can not change the text of a button after it has be created. I
>> really don't like that possibility. The user can only set the text of the
>> three special buttons in the constructor.
>
>In this case you simply missed the setButtonApplyText(..) and related methods. It sets
>the button texts, tooltips and quickhelps for the predefined buttons.
>
Again I was unclear. I do not want to give the user the posibility to change the
text of the action buttons. Ok, it should normally only be done when creating
the dialog, but nothing prevents (at least what I can see :) the user to change 
the button text later. If this posibility exists, it will be used (ie. abused)
sooner or later.


CDialogCore::CDialogCore( int dialogType, int buttonMask, int defaultButton,
			  QWidget *parent, const char *name,
			  const QString &title, bool separator, bool modal,
			  const QString &user1, const QString &user2,
			  const QString &user3 )
  : QDialog( parent, name, modal, WStyle_Customize|WStyle_DialogBorder )
{

  setCaption( kapp->getCaption() + ": " + title );

  mTopLayout = new QVBoxLayout( this );
  if( mTopLayout == 0 ) { return; }

  mPageList = 0;
  mTreeNodeList = 0;
  mTitleList = 0;
  mActivePageWidget = 0;
  mActivePageIndex = -1;

  if( dialogType == TreeList )
  {
    mPageList = new QList<QWidget>;
    if( mPageList == 0 ) { return; }

    mTreeNodeList = new QList<QListViewItem>;
    if( mTreeNodeList == 0 ) { return; }

    mTitleList = new QStringList();
    if( mTitleList == 0 ) { return; }

    mDialogType = dialogType;

    QSplitter *splitter = new QSplitter( this );
    mTopLayout->addWidget( splitter );

    //
    // Tree list
    //
    mTreeList = new QListView( splitter );
    mTreeList->addColumn( QString("") );
    mTreeList->header()->hide();
    mTreeList->setRootIsDecorated(true);
    mTreeList->setSorting( -1 );
    connect( mTreeList, SIGNAL(selectionChanged()), SLOT(slotShowPage()) );

    //
    // Page area. Title at top with a separator below and a pagestack using
    // all available space at bottom.
    //
    QFrame *page = new QFrame( splitter );
    if( page == 0 ) { return; }
    page->setFrameStyle( QFrame::Panel|QFrame::Raised );

    QVBoxLayout *vbox = new QVBoxLayout( page, outerMarginHint(), 0 );
    if( vbox == 0 ) { return; }
    mTitleLabel = new QLabel( QString("Empty page"), page );
    vbox->addWidget( mTitleLabel );
    
    QFont titleFont( mTitleLabel->font() );
    titleFont.setBold( true );
    mTitleLabel->setFont( titleFont );

    vbox->addSpacing( outerMarginHint() );
    KSeparator *sep = new KSeparator( page );
    sep->setOrientation( QFrame::HLine );
    sep->setFrameStyle( QFrame::HLine|QFrame::Plain );

    vbox->addWidget( sep );
    vbox->addSpacing( innerMarginHint() );

    mPageStack = new QWidgetStack( page );
    if( mPageStack == 0 ) { return; }
    vbox->addWidget( mPageStack, 10 );
    vbox->activate();
  }
  else if( dialogType == Tabbed )
  {
    mPageList = new QList<QWidget>;
    if( mPageList == 0 ) { return; }
  
    mDialogType = Tabbed;
    
    mTopLayout->addSpacing( outerMarginHint() );
    QHBoxLayout *hbox = new QHBoxLayout();
    mTopLayout->addLayout( hbox, 10 );

    mTabControl = new KTabCtl( this );
    hbox->addSpacing( outerMarginHint() );
    hbox->addWidget( mTabControl, 10 );
    hbox->addSpacing( outerMarginHint() );
  }
  else
  {
    mDialogType = Plain;

    mTopLayout->addSpacing( outerMarginHint() );
    QHBoxLayout *hbox = new QHBoxLayout();
    mTopLayout->addLayout( hbox, 10 );
   
    mPlainPage = new QWidget( this );
    hbox->addSpacing( outerMarginHint() );
    hbox->addWidget( mPlainPage, 10 );
    hbox->addSpacing( outerMarginHint() );
  }

  if( separator == true )
  {
    KSeparator *sep = new KSeparator( this );
    sep->setOrientation( QFrame::HLine );

    if( dialogType != TreeList )
    {
      mTopLayout->addSpacing( innerMarginHint() );
      QHBoxLayout *hbox = new QHBoxLayout();
      mTopLayout->addLayout( hbox );
      hbox->addSpacing( outerMarginHint() );
      hbox->addWidget( sep, 10 );
      hbox->addSpacing( outerMarginHint() );
    }
    else
    {
      mTopLayout->addWidget( sep );
    }
  }


  if( buttonMask & (Cancel|Close) == 0 ) { buttonMask |= Cancel; }
  if( buttonMask & Cancel ) { buttonMask &= ~Close; }
  
  KButtonBox *buttonBox = new KButtonBox( this, KButtonBox::HORIZONTAL, 
					outerMarginHint(), innerMarginHint() );
  mButton.mask = buttonMask;
  if( mButton.mask & Help )
  {
    mButton.help = buttonBox->addButton( i18n("&Help"), false );
    if( defaultButton == Help ) setDefaultFocus( mButton.help, true, true );
    connect(mButton.help,SIGNAL(clicked()),SLOT(slotHelp()));
  }
  if( mButton.mask & Default )
  {
    mButton.def = buttonBox->addButton( i18n("&Default"), false );
    if( defaultButton == Default ) setDefaultFocus( mButton.def, true, true );
    connect(mButton.def,SIGNAL(clicked()),SLOT(slotDefault()));
  }

  // Always a strecth here
  buttonBox->addStretch();

  if( mButton.mask & User3 )
  {
    mButton.user3 = buttonBox->addButton( user3, false );
    if( defaultButton == User3 ) setDefaultFocus( mButton.user3, true, true );
    connect(mButton.user3,SIGNAL(clicked()),SLOT(slotUser3()));
  }
  if( mButton.mask & User2 )
  {
    mButton.user2 = buttonBox->addButton( user2, false );
    if( defaultButton == User2 ) setDefaultFocus( mButton.user2, true, true );
    connect(mButton.user2,SIGNAL(clicked()),SLOT(slotUser2()));
  }
  if( mButton.mask & User1 )
  {
    mButton.user1 = buttonBox->addButton( user1, false );
    if( defaultButton == User1 ) setDefaultFocus( mButton.user1, true, true );
    connect(mButton.user1,SIGNAL(clicked()),SLOT(slotUser1()));
  }

  if( mButton.mask & Ok )
  {
    mButton.ok = buttonBox->addButton( i18n("&OK"), false );
    if( defaultButton == Ok ) setDefaultFocus( mButton.ok, true, true );
    connect(mButton.ok,SIGNAL(clicked()),SLOT(slotOk()));
  }
  if( mButton.mask & Apply )
  {
    mButton.apply = buttonBox->addButton( i18n("&Apply"), false );
    if( defaultButton == Apply ) setDefaultFocus( mButton.apply, true, true );
    connect(mButton.apply,SIGNAL(clicked()),SLOT(slotApply()));
  }
  if( mButton.mask & Cancel )
  {
    mButton.cancel = buttonBox->addButton( i18n("&Cancel"), false );
    if( defaultButton == Cancel ) setDefaultFocus( mButton.cancel, true, true);
    connect(mButton.cancel,SIGNAL(clicked()),SLOT(slotCancel()));
  }
  if( mButton.mask & Close )
  {
    mButton.close = buttonBox->addButton( i18n("&Close"), false );
    if( defaultButton == Close ) setDefaultFocus( mButton.close, true, true );
    connect(mButton.close,SIGNAL(clicked()),SLOT(slotClose()));
  }


  buttonBox->layout();
  buttonBox->setMinimumSize( buttonBox->sizeHint() );
  mTopLayout->addWidget( buttonBox );

  mIsActivated = false;
  connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged()));
}













-- 
Espen Sand

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

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