20#include "KoContextCelp.h"
27#include <tqsimplerichtext.h>
32#include <kiconloader.h>
34#include <tdeapplication.h>
37KoVerticalLabel::KoVerticalLabel( TQWidget* parent,
const char* name )
38 : TQWidget( parent,
name, TQt::WRepaintNoErase )
41 f.setPointSize( f.pointSize() + 2 );
44 setBackgroundMode( PaletteLight );
47KoVerticalLabel::~KoVerticalLabel()
51void KoVerticalLabel::setText(
const TQString& text )
54 TQFontMetrics fm( font() );
55 setMinimumSize( fm.height() + 2, fm.width( m_text ) + 4 );
59void KoVerticalLabel::paintEvent( TQPaintEvent* )
62 pm.resize( height(), width() );
64 p.fillRect( 0, 0, height(), width(), colorGroup().background() );
66 p.drawText( 0, 0, height(), width(), AlignCenter, m_text );
70 ap.translate( -height(), 0 );
71 ap.drawPixmap( 0, 0, pm );
74static unsigned char upbits[] = { 0xc, 0x1e, 0x3f, 0x3f };
75static unsigned char downbits[] = { 0x3f, 0x3f, 0x1e, 0xc };
77KoHelpNavButton::KoHelpNavButton( NavDirection d, TQWidget* parent )
81 m_bitmap = TQBitmap( 8, 4, ( d == Up ? upbits : downbits ), true );
82 m_bitmap.setMask( m_bitmap );
84 setBackgroundMode( PaletteLight );
87void KoHelpNavButton::paintEvent( TQPaintEvent* )
93 p.setPen( colorGroup().highlight() );
95 p.setPen( colorGroup().text() );
96 p.drawPixmap( 1, 1, m_bitmap );
100void KoHelpNavButton::enterEvent( TQEvent* )
108void KoHelpNavButton::leaveEvent( TQEvent* )
116static unsigned char notstickybits[] = { 0x8, 0x1e, 0xc, 0xa, 0x1 };
117static unsigned char stickybits[] = { 0xe, 0x11, 0x15, 0x11, 0xe };
118static unsigned char closebits[] = { 0x11, 0xa, 0x4, 0xa, 0x11 };
120KoTinyButton::KoTinyButton( Action a, TQWidget* parent )
121 : TQWidget( parent ), m_action( a )
128 m_bitmap = TQBitmap( 5, 5, notstickybits,
true );
132 m_bitmap = TQBitmap( 5, 5, closebits,
true );
134 m_bitmap.setMask( m_bitmap );
135 setMinimumSize( 7, 7 );
136 setBackgroundMode( PaletteBackground );
139void KoTinyButton::paintEvent( TQPaintEvent* )
145 p.setPen( colorGroup().highlight() );
147 p.setPen( colorGroup().text() );
148 p.drawPixmap( width() / 2 - 2, 1, m_bitmap );
152void KoTinyButton::mousePressEvent( TQMouseEvent* )
161void KoTinyButton::mouseReleaseEvent( TQMouseEvent* )
163 if ( isEnabled() && m_pressed )
167 if ( ( m_action == Sticky ) )
169 m_toggled = !m_toggled;
170 emit( toggled( m_toggled ) );
174 m_bitmap = TQBitmap( 5, 5, ( m_toggled ? stickybits : notstickybits ), true );
176 m_bitmap.setMask( m_bitmap );
182KoHelpView::KoHelpView( TQWidget* parent )
186 setBackgroundMode( PaletteLight );
187 parent->installEventFilter(
this );
188 setMouseTracking(
true );
191KoHelpView::~KoHelpView()
197void KoHelpView::setText(
const TQString& text )
201 currentText =
new TQSimpleRichText( text, font() );
202 currentText->setWidth( width() );
203 setFixedHeight( currentText->height() );
206void KoHelpView::mousePressEvent( TQMouseEvent* e )
208 currentAnchor = currentText->anchorAt( e->pos() );
209 if ( !currentAnchor.isEmpty() )
215void KoHelpView::mouseReleaseEvent( TQMouseEvent* e )
217 if ( ( !currentAnchor.isEmpty() ) && ( currentAnchor == currentText->anchorAt( e->pos() ) ) )
220 if (currentAnchor.startsWith(
"help://#")) {
222 kapp->invokeHelp(currentAnchor.right(currentAnchor.length()-8));
225 if (currentAnchor.startsWith(
"help://")) {
227 TQString helpapp=currentAnchor.right(currentAnchor.length()-7);
230 if ((pos=helpapp.find(
"#"))!=-1) {
231 helpanchor=helpapp.right(helpapp.length()-pos-1);
232 helpapp=helpapp.left(pos);
234 kapp->invokeHelp(helpanchor,helpapp);
237 emit linkClicked( currentAnchor );
244void KoHelpView::mouseMoveEvent( TQMouseEvent* e )
246 if ( !currentText->anchorAt( e->pos() ).isEmpty() )
252bool KoHelpView::eventFilter( TQObject*, TQEvent* e )
254 if ( ( currentText ) && ( e->type() == TQEvent::Resize ) )
256 setFixedWidth( ( (TQResizeEvent*)e )->size().width() );
257 currentText->setWidth( width() );
258 setFixedHeight( currentText->height() );
265void KoHelpView::paintEvent( TQPaintEvent* )
268 currentText->draw( &p, 0, 0, TQRect(), colorGroup() );
271KoHelpWidget::KoHelpWidget( TQString help, TQWidget* parent )
274 TQGridLayout* layout =
new TQGridLayout(
this, 3, 3 );
275 layout->setMargin( 2 );
276 layout->addWidget( m_upButton =
new KoHelpNavButton( KoHelpNavButton::Up,
this ), 0, 1, AlignHCenter );
277 layout->addWidget( m_helpViewport =
new TQWidget(
this ), 1, 1 );
278 layout->addWidget( m_downButton =
new KoHelpNavButton( KoHelpNavButton::Down,
this ), 2, 1, AlignHCenter );
279 layout->addColSpacing( 0, 5 );
280 layout->addColSpacing( 2, 5 );
281 layout->setColStretch( 1, 1 );
283 m_helpView =
new KoHelpView( m_helpViewport );
284 m_helpViewport->setBackgroundMode( PaletteLight );
287 setBackgroundMode( PaletteLight );
289 connect( m_upButton, TQ_SIGNAL( pressed() ),
this, TQ_SLOT( startScrollingUp() ) );
290 connect( m_downButton, TQ_SIGNAL( pressed() ),
this, TQ_SLOT( startScrollingDown() ) );
291 connect( m_upButton, TQ_SIGNAL( released() ),
this, TQ_SLOT( stopScrolling() ) );
292 connect( m_downButton, TQ_SIGNAL( released() ),
this, TQ_SLOT( stopScrolling() ) );
293 connect( m_helpView, TQ_SIGNAL( linkClicked(
const TQString& ) ),
this, TQ_SIGNAL( linkClicked(
const TQString& ) ) );
296void KoHelpWidget::updateButtons()
298 m_upButton->setEnabled( m_ypos < 0 );
299 m_downButton->setEnabled( m_helpViewport->height() - m_ypos < m_helpView->height() );
302void KoHelpWidget::setText( TQString text )
304 m_helpView->setText( text );
305 m_helpView->move( 0, 0 );
310void KoHelpWidget::resizeEvent( TQResizeEvent* )
315void KoHelpWidget::startScrollingUp()
317 if ( !m_upButton->isEnabled() )
319 m_scrollDown =
false;
323void KoHelpWidget::startScrollingDown()
325 if ( !m_downButton->isEnabled() )
331void KoHelpWidget::scrollUp()
338 m_helpViewport->scroll( 0, 2 );
339 m_helpViewport->update();
344void KoHelpWidget::scrollDown()
346 if ( m_helpViewport->height() - m_helpView->height() - m_ypos > 0 )
351 m_helpViewport->scroll( 0, -2 );
352 m_helpViewport->update();
357void KoHelpWidget::timerEvent( TQTimerEvent* )
365void KoHelpWidget::stopScrolling()
370KoContextHelpPopup::KoContextHelpPopup( TQWidget* parent )
371 : TQWidget( parent,
"", WType_Dialog | WStyle_Customize | WStyle_NoBorder )
373 TQGridLayout* layout =
new TQGridLayout(
this );
374 TQHBoxLayout* buttonLayout;
375 layout->addWidget( m_helpIcon =
new TQLabel(
this ), 0, 0 );
376 layout->addWidget( m_helpTitle =
new KoVerticalLabel(
this ), 1, 0 );
377 buttonLayout =
new TQHBoxLayout( layout );
379 layout->addMultiCellWidget( m_helpViewer =
new KoHelpWidget(
"",
this ), 0, 2, 1, 1 );
380 buttonLayout->add( m_close =
new KoTinyButton( KoTinyButton::Close,
this ) );
381 buttonLayout->add( m_sticky =
new KoTinyButton( KoTinyButton::Sticky,
this ) );
382 layout->addColSpacing( 2, 2 );
383 layout->addRowSpacing( 3, 2 );
384 layout->setMargin( 3 );
385 layout->setSpacing( 1 );
386 layout->setRowStretch( 1, 1 );
387 buttonLayout->setSpacing( 1 );
388 setMinimumSize( 180, 180 );
391 setFocusPolicy( TQWidget::StrongFocus );
393 connect( m_close, TQ_SIGNAL( clicked() ),
this, TQ_SIGNAL( wantsToBeClosed() ) );
394 connect( m_sticky, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( setSticky(
bool ) ) );
395 connect( m_helpViewer, TQ_SIGNAL( linkClicked(
const TQString& ) ),
this, TQ_SIGNAL( linkClicked(
const TQString& ) ) );
398KoContextHelpPopup::~KoContextHelpPopup()
402void KoContextHelpPopup::setContextHelp(
const TQString& title,
const TQString& text,
const TQPixmap* icon )
404 m_helpIcon->setPixmap( icon ? *icon : BarIcon(
"help" ) );
405 m_helpTitle->setText( title );
406 m_helpViewer->setText( text );
409void KoContextHelpPopup::mousePressEvent( TQMouseEvent* e )
411 m_mousePos = e->globalPos() - pos();
414void KoContextHelpPopup::mouseMoveEvent( TQMouseEvent* e )
416 move( e->globalPos() - m_mousePos );
419void KoContextHelpPopup::resizeEvent( TQResizeEvent* )
421 TQBitmap mask( width(), height() );
423 TQPainter p( &mask );
424 p.fillRect( 0, 0, width(), height(), color1 );
426 p.setBrush( color0 );
427 p.drawLine( 0, 0, 0, 3 );
428 p.drawLine( 0, 0, 3, 0 );
430 a.setPoints( 3, 0, height() - 5, 4, height() - 1, 0, height() - 1 );
432 a.setPoints( 3, width() - 5, 0, width() - 1, 4, width() - 1, 0 );
434 p.drawLine( width() - 1, height() - 1, width() - 4, height() - 1 );
435 p.drawLine( width() - 1, height() - 1, width() - 1, height() - 4 );
436 p.drawPoint( width() - 2, height() - 2 );
437 p.drawPoint( 0, height() - 6 );
438 p.drawPoint( width() - 6, 0 );
439 p.drawPoint( width() - 5, height() - 3 );
440 p.drawPoint( width() - 3, height() - 5 );
442 p.setBrush( TQBrush( color0, Dense4Pattern ) );
443 p.drawRect( 0, height() - 2, width() - 1, height() - 1 );
444 p.drawRect( width() - 2, 0, width() - 1, height() - 1 );
445 p.drawRect( width() - 4, height() - 4, width() - 2, height() - 2 );
447 setMask( TQRegion( mask ) );
450void KoContextHelpPopup::paintEvent( TQPaintEvent* )
453 p.fillRect( 0, 0, width(), height(), colorGroup().light() );
455 p.drawRect( 0, 0, width(), height() );
456 p.fillRect( width() - 3, 0, width() - 1, height() - 1, black );
457 p.fillRect( 0, height() - 3, width() - 1, height() - 1, black );
458 p.drawLine( 1, 2, 1, 3 );
459 p.drawLine( 2, 1, 3, 1 );
460 p.drawLine( width() - 4, 2, width() - 4, 3 );
461 p.drawLine( width() - 5, 1, width() - 6, 1 );
462 p.drawLine( 1, height() - 5, 1, height() - 6 );
463 p.drawLine( 2, height() - 4, 3, height() - 4 );
464 p.drawLine( width() - 4, height() - 5, width() - 4, height() - 6 );
465 p.drawLine( width() - 4, height() - 4, width() - 6, height() - 4 );
468void KoContextHelpPopup::windowActivationChange(
bool )
470 if ( !isActiveWindow() && !m_isSticky )
471 emit wantsToBeClosed();
474void KoContextHelpPopup::keyPressEvent( TQKeyEvent* e )
486 m_helpViewer->scrollUp();
490 m_helpViewer->scrollDown();
495void KoContextHelpPopup::keyReleaseEvent( TQKeyEvent* e )
505 emit wantsToBeClosed();
511 :
TDEToggleAction( i18n(
"Context Help" ), BarIcon(
"help" ), TDEShortcut(
"CTRL+SHIFT+F1" ), 0, 0, parent,
"help_context" )
514 connect( m_popup, TQ_SIGNAL( wantsToBeClosed() ),
this, TQ_SLOT( closePopup() ) );
515 connect(
this, TQ_SIGNAL( toggled(
bool ) ), m_popup, TQ_SLOT( setShown(
bool ) ) );
516 connect( m_popup, TQ_SIGNAL( linkClicked(
const TQString& ) ),
this, TQ_SIGNAL( linkClicked(
const TQString& ) ) );
519KoContextHelpAction::~KoContextHelpAction()
524void KoContextHelpAction::updateHelp(
const TQString& title,
const TQString& text,
const TQPixmap* icon )
526 m_popup->setContextHelp( title,
text, icon );
529void KoContextHelpAction::closePopup()
536KoContextHelpWidget::KoContextHelpWidget( TQWidget* parent,
const char* name )
537 : TQWidget( parent,
name )
539 setCaption( i18n(
"Context Help" ) );
540 TQGridLayout* layout =
new TQGridLayout(
this );
541 layout->addWidget( m_helpIcon =
new TQLabel(
this ), 0, 0 );
542 layout->addWidget( m_helpTitle =
new KoVerticalLabel(
this ), 1, 0 );
543 layout->addMultiCellWidget( m_helpViewer =
new KoHelpWidget(
"",
this ), 0, 1, 1, 1 );
544 layout->setMargin( 2 );
545 layout->setSpacing( 1 );
546 layout->setRowStretch( 1, 1 );
547 this->setMinimumSize( 180, 120 );
549 setContextHelp( i18n(
"Context Help" ), i18n(
"Here will be shown help according to your actions" ), 0 );
550 connect( m_helpViewer, TQ_SIGNAL( linkClicked(
const TQString& ) ),
this, TQ_SIGNAL( linkClicked(
const TQString& ) ) );
553KoContextHelpWidget::~KoContextHelpWidget()
557void KoContextHelpWidget::setContextHelp(
const TQString& title,
const TQString& text,
const TQPixmap* icon )
559 m_helpIcon->setPixmap( icon ? *icon : BarIcon(
"help" ) );
560 m_helpTitle->setText( title );
561 m_helpViewer->setText( text );
565KoContextHelpDocker::KoContextHelpDocker( TQWidget* parent,
const char* name )
566 : TQDockWindow( parent,
name )
568 setCaption( i18n(
"Context Help" ) );
569 TQWidget* mainWidget =
new TQWidget(
this );
570 TQGridLayout* layout =
new TQGridLayout( mainWidget );
571 layout->addWidget( m_helpIcon =
new TQLabel( mainWidget ), 0, 0 );
572 layout->addWidget( m_helpTitle =
new KoVerticalLabel( mainWidget ), 1, 0 );
573 layout->addMultiCellWidget( m_helpViewer =
new KoHelpWidget(
"", mainWidget ), 0, 1, 1, 1 );
574 layout->setMargin( 2 );
575 layout->setSpacing( 1 );
576 layout->setRowStretch( 1, 1 );
577 mainWidget->setMinimumSize( 180, 120 );
579 setWidget( mainWidget );
580 setContextHelp( i18n(
"Context Help" ), i18n(
"Here will be shown help according to your actions" ), 0 );
581 connect( m_helpViewer, TQ_SIGNAL( linkClicked(
const TQString& ) ),
this, TQ_SIGNAL( linkClicked(
const TQString& ) ) );
584KoContextHelpDocker::~KoContextHelpDocker()
588void KoContextHelpDocker::setContextHelp(
const TQString& title,
const TQString& text,
const TQPixmap* icon )
590 m_helpIcon->setPixmap( icon ? *icon : BarIcon(
"help" ) );
591 m_helpTitle->setText( title );
592 m_helpViewer->setText( text );
595#include "KoContextCelp.moc"
static TQCursor arrowCursor()
static TQCursor handCursor()
virtual TQString text() const
virtual void setChecked(bool)
const char * name(StdAction id)