rc_DATA = threadtabwidgetui.rc
-noinst_HEADERS = domtree.h htmlpart.h threadtabwidget.h threadview.h
-libkitathread_la_SOURCES = domtree.cpp htmlpart.cpp threadtabwidget.cpp threadview.cpp
+noinst_HEADERS = domtree.h htmlpart.h threadtabwidget.h threadview.h respopup.h
+libkitathread_la_SOURCES = domtree.cpp htmlpart.cpp threadtabwidget.cpp \
+ threadview.cpp respopup.cpp
#include "htmlpart.h"
#include "domtree.h"
+#include "respopup.h"
#include "kitaui/htmlview.h"
/* class ResPopup */
-namespace Kita
-{
- ResPopup::ResPopup( KHTMLView* view, const KURL& url )
- : QFrame( view, "res_popup",
- WStyle_Customize
- | WStyle_NoBorder
- | WStyle_Tool
- | WType_TopLevel
- | WX11BypassWM
- )
- {
- m_url = url;
- m_htmlPart = NULL;
-
- m_htmlPart = new KitaHTMLPart( this );
- m_htmlPart->setup( HTMLPART_MODE_POPUP , url );
- connect( m_htmlPart, SIGNAL( hideChildPopup() ), SIGNAL( hideChildPopup() ) );
- }
-
-
- ResPopup::~ResPopup()
- {
- if ( m_htmlPart ) delete m_htmlPart;
- }
-
-
-
- /* public */
- void ResPopup::setText( const QString& str )
- {
- const int maxwd = 1600;
- const int maxht = 1200;
-
- QString style = QString( "body.pop {"
- " font-size: %1pt; "
- " font-family: %2; "
- " color: %3; "
- " background-color: %4; "
- " border-width: 0;"
- "}" )
- .arg( Kita::Config::popupFont().pointSize() )
- .arg( Kita::Config::popupFont().family() )
- .arg( Kita::Config::popupColor().name() )
- .arg( Kita::Config::popupBackground().name() );
-
- QString text = "<html><head><style>";
- text += KitaConfig::defaultStyleSheetText();
- text += style;
- if ( Kita::Config::useStyleSheet() ) {
- text += KitaConfig::styleSheetText();
- }
- text += "</style></head><body class=\"pop\">";
- text += str;
- text += "</body></html>";
-
- if ( m_htmlPart ) {
- m_htmlPart->view() ->resize( maxwd, maxht );
- m_htmlPart->setJScriptEnabled( false );
- m_htmlPart->setJavaEnabled( false );
- m_htmlPart->begin( "file:/dummy.htm" );
- m_htmlPart->write( text );
- m_htmlPart->end();
- m_htmlPart->view() ->setVScrollBarMode( QScrollView::AlwaysOff );
- }
- }
-
-
- /* public */
- void ResPopup::adjustSize()
- {
- if ( !m_htmlPart ) return ;
-
- int width = 0, xx = 0, leftmrg = 0;
- int maxwidth = 0, maxheight = 0;
- DOM::Node curnode = m_htmlPart->htmlDocument().body().firstChild();
-
- for ( ;; ) {
-
- QRect qr = curnode.getRect();
- int tmpwd = qr.right() - qr.left();
-
- /*----------------------------------*/
-
- if ( curnode.nodeType() == DOM::Node::TEXT_NODE ) {
- if ( xx == 0 ) xx = qr.left();
- width += tmpwd;
- }
-
- /*----------------------------------*/
-
- else if ( curnode.nodeName().string() == "div" ) {
- if ( leftmrg == 0 ) leftmrg = qr.left();
- width = 0;
- xx = 0;
- }
-
- /*----------------------------------*/
-
- else if ( curnode.nodeName().string() == "br" ) {
- width = 0;
- xx = 0;
- }
-
-
- /*----------------------------------*/
-
- if ( leftmrg + xx + width > maxwidth ) maxwidth = leftmrg + xx + width;
- if ( qr.bottom() > maxheight ) maxheight = qr.bottom();
-
- /* move to the next node */
- DOM::Node next = curnode.firstChild();
-
- if ( next.isNull() ) next = curnode.nextSibling();
-
- while ( !curnode.isNull() && next.isNull() ) {
- curnode = curnode.parentNode();
- if ( !curnode.isNull() ) next = curnode.nextSibling();
- }
-
- curnode = next;
-
- if ( curnode.isNull() ) break;
- }
-
- const int mrg = 32;
-
- int wd = maxwidth + mrg;
- int ht = maxheight + mrg;
-
- m_htmlPart->view() ->resize( wd, ht );
- QFrame::adjustSize();
- }
-
-
- /* public */
- void ResPopup::adjustPos( QPoint pos )
- {
- enum{
- POS_LeftUp,
- POS_RightUp,
- POS_LeftDown,
- POS_RightDown
- };
-
- /* config */
-
- const int mrg = 16;
-
- /*----------------------------*/
-
- if ( !m_htmlPart ) return ;
-
- QRect qr = QApplication::desktop() ->rect();
- int sw = qr.width(), sh = qr.height();
- int wd = width(), ht = height();
- int x = pos.x(), y = pos.y();
- int idx;
-
- if ( ( x + mrg ) + wd < sw
- && ( y - mrg ) - ht >= 0 ) idx = POS_RightUp;
-
- else if ( ( x - mrg ) - wd >= 0
- && y - ( ht + mrg ) >= 0 ) idx = POS_LeftUp;
-
- else if ( ( x + mrg ) + wd < sw
- && ( y + mrg ) + ht < sh ) idx = POS_RightDown;
-
- else if ( ( x - mrg ) - wd >= 0
- && ( y + mrg ) + ht < sh ) idx = POS_LeftDown;
-
- else {
- int area[ 4 ];
- area[ 0 ] = ( sw - x ) * y;
- area[ 1 ] = x * y;
- area[ 2 ] = ( sw - x ) * ( sh - y );
- area[ 3 ] = x * ( sh - y );
-
- idx = 0;
- for ( int i = 1; i < 4; ++i ) if ( area[ i ] > area[ idx ] ) idx = i;
- }
-
- switch ( idx ) {
-
- case POS_RightUp:
- x = x + mrg;
- y = ( y - mrg ) - ht;
- break;
-
- case POS_LeftUp:
- x = ( x - mrg ) - wd;
- y = ( y - mrg ) - ht;
- break;
-
- case POS_RightDown:
- x = x + mrg;
- y = y + mrg;
- break;
-
- case POS_LeftDown:
- x = ( x - mrg ) - wd;
- y = y + mrg;
- break;
- }
-
- if ( x < 0 ) {
-
- x = ht % 16;
- }
- if ( x + wd >= sw ) {
-
- x = sw - wd - ( ht % 16 );
-
- if ( x < 0 ) {
- if ( m_htmlPart ) m_htmlPart->view() ->setVScrollBarMode( QScrollView::AlwaysOn );
- x = 0;
- wd = sw;
- }
- }
-
- if ( y < 0 ) {
- if ( x <= pos.x() && pos.x() < x + wd ) {
- if ( m_htmlPart ) m_htmlPart->view() ->setVScrollBarMode( QScrollView::AlwaysOn );
- ht += y;
- }
- y = 0;
- }
- if ( y + ht >= sh ) {
-
- if ( x <= pos.x() && pos.x() < x + wd ) {
- if ( m_htmlPart ) m_htmlPart->view() ->setVScrollBarMode( QScrollView::AlwaysOn );
- ht = sh - y;
- } else {
- y = sh - ht;
-
- if ( y < 0 ) {
- if ( m_htmlPart ) m_htmlPart->view() ->setVScrollBarMode( QScrollView::AlwaysOn );
- y = 0;
- ht = sh;
- }
- }
- }
-
- pos.setX( x );
- pos.setY( y );
- move( pos );
-
- if ( m_htmlPart ) m_htmlPart->view() ->resize( wd, ht );
- resize( wd , ht );
- }
-
-
- /* move mouse pointer above the popup frame */ /* public */
- void ResPopup::moveMouseAbove()
- {
- /* config */
-
- const int mrg = 10;
-
- /*-------------------------------*/
-
- QPoint pos = QCursor::pos();
- int cx = pos.x(), cy = pos.y();
- int px = x();
- int py = y();
- int wd = width();
- int ht = height();
-
- if ( cx <= px ) cx = px + mrg;
- else if ( cx >= px + wd ) cx = px + wd - mrg;
-
- if ( cy <= py ) cy = py + mrg;
- else if ( cy >= py + ht ) cy = py + ht - mrg;
-
- QCursor::setPos( cx, cy );
- }
-}
-
/*---------------------------------------------------*/
-namespace Kita
-{
- class ResPopup : public QFrame
- {
- Q_OBJECT
-
- KitaHTMLPart* m_htmlPart;
- KURL m_url;
-
-
- public:
- ResPopup( KHTMLView* view, const KURL& datURL );
- ~ResPopup();
- void setText( const QString& str );
- void adjustSize();
- void adjustPos( QPoint pos );
- void moveMouseAbove();
-
- private:
- void showImage( const KURL& url );
-
- signals:
- void hideChildPopup();
- };
-}
/* user defined events */
--- /dev/null
+/***************************************************************************
+* Copyright (C) 2007 by Kita Developers *
+* ikemo@users.sourceforge.jp *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#include "respopup.h"
+
+#include <qapplication.h>
+#include <qcursor.h>
+
+#include <dom/html_element.h>
+
+#include "kitaui/htmlview.h"
+
+#include "libkita/config_xt.h"
+#include "libkita/kitaconfig.h"
+
+namespace Kita
+{
+ ResPopup::ResPopup( KHTMLView* view, const KURL& url )
+ : QFrame( view, "res_popup",
+ WStyle_Customize
+ | WStyle_NoBorder
+ | WStyle_Tool
+ | WType_TopLevel
+ | WX11BypassWM
+ )
+ {
+ m_url = url;
+ m_htmlPart = NULL;
+
+ m_htmlPart = new KitaHTMLPart( this );
+ m_htmlPart->setup( HTMLPART_MODE_POPUP , url );
+ connect( m_htmlPart, SIGNAL( hideChildPopup() ), SIGNAL( hideChildPopup() ) );
+ }
+
+
+ ResPopup::~ResPopup()
+ {
+ if ( m_htmlPart ) delete m_htmlPart;
+ }
+
+
+
+ /* public */
+ void ResPopup::setText( const QString& str )
+ {
+ const int maxwd = 1600;
+ const int maxht = 1200;
+
+ QString style = QString( "body.pop {"
+ " font-size: %1pt; "
+ " font-family: %2; "
+ " color: %3; "
+ " background-color: %4; "
+ " border-width: 0;"
+ "}" )
+ .arg( Kita::Config::popupFont().pointSize() )
+ .arg( Kita::Config::popupFont().family() )
+ .arg( Kita::Config::popupColor().name() )
+ .arg( Kita::Config::popupBackground().name() );
+
+ QString text = "<html><head><style>";
+ text += KitaConfig::defaultStyleSheetText();
+ text += style;
+ if ( Kita::Config::useStyleSheet() ) {
+ text += KitaConfig::styleSheetText();
+ }
+ text += "</style></head><body class=\"pop\">";
+ text += str;
+ text += "</body></html>";
+
+ if ( m_htmlPart ) {
+ m_htmlPart->view() ->resize( maxwd, maxht );
+ m_htmlPart->setJScriptEnabled( false );
+ m_htmlPart->setJavaEnabled( false );
+ m_htmlPart->begin( "file:/dummy.htm" );
+ m_htmlPart->write( text );
+ m_htmlPart->end();
+ m_htmlPart->view() ->setVScrollBarMode( QScrollView::AlwaysOff );
+ }
+ }
+
+
+ /* public */
+ void ResPopup::adjustSize()
+ {
+ if ( !m_htmlPart ) return ;
+
+ int width = 0, xx = 0, leftmrg = 0;
+ int maxwidth = 0, maxheight = 0;
+ DOM::Node curnode = m_htmlPart->htmlDocument().body().firstChild();
+
+ for ( ;; ) {
+
+ QRect qr = curnode.getRect();
+ int tmpwd = qr.right() - qr.left();
+
+ /*----------------------------------*/
+
+ if ( curnode.nodeType() == DOM::Node::TEXT_NODE ) {
+ if ( xx == 0 ) xx = qr.left();
+ width += tmpwd;
+ }
+
+ /*----------------------------------*/
+
+ else if ( curnode.nodeName().string() == "div" ) {
+ if ( leftmrg == 0 ) leftmrg = qr.left();
+ width = 0;
+ xx = 0;
+ }
+
+ /*----------------------------------*/
+
+ else if ( curnode.nodeName().string() == "br" ) {
+ width = 0;
+ xx = 0;
+ }
+
+
+ /*----------------------------------*/
+
+ if ( leftmrg + xx + width > maxwidth ) maxwidth = leftmrg + xx + width;
+ if ( qr.bottom() > maxheight ) maxheight = qr.bottom();
+
+ /* move to the next node */
+ DOM::Node next = curnode.firstChild();
+
+ if ( next.isNull() ) next = curnode.nextSibling();
+
+ while ( !curnode.isNull() && next.isNull() ) {
+ curnode = curnode.parentNode();
+ if ( !curnode.isNull() ) next = curnode.nextSibling();
+ }
+
+ curnode = next;
+
+ if ( curnode.isNull() ) break;
+ }
+
+ const int mrg = 32;
+
+ int wd = maxwidth + mrg;
+ int ht = maxheight + mrg;
+
+ m_htmlPart->view() ->resize( wd, ht );
+ QFrame::adjustSize();
+ }
+
+
+ /* public */
+ void ResPopup::adjustPos( QPoint pos )
+ {
+ enum{
+ POS_LeftUp,
+ POS_RightUp,
+ POS_LeftDown,
+ POS_RightDown
+ };
+
+ /* config */
+
+ const int mrg = 16;
+
+ /*----------------------------*/
+
+ if ( !m_htmlPart ) return ;
+
+ QRect qr = QApplication::desktop() ->rect();
+ int sw = qr.width(), sh = qr.height();
+ int wd = width(), ht = height();
+ int x = pos.x(), y = pos.y();
+ int idx;
+
+ if ( ( x + mrg ) + wd < sw
+ && ( y - mrg ) - ht >= 0 ) idx = POS_RightUp;
+
+ else if ( ( x - mrg ) - wd >= 0
+ && y - ( ht + mrg ) >= 0 ) idx = POS_LeftUp;
+
+ else if ( ( x + mrg ) + wd < sw
+ && ( y + mrg ) + ht < sh ) idx = POS_RightDown;
+
+ else if ( ( x - mrg ) - wd >= 0
+ && ( y + mrg ) + ht < sh ) idx = POS_LeftDown;
+
+ else {
+ int area[ 4 ];
+ area[ 0 ] = ( sw - x ) * y;
+ area[ 1 ] = x * y;
+ area[ 2 ] = ( sw - x ) * ( sh - y );
+ area[ 3 ] = x * ( sh - y );
+
+ idx = 0;
+ for ( int i = 1; i < 4; ++i ) if ( area[ i ] > area[ idx ] ) idx = i;
+ }
+
+ switch ( idx ) {
+
+ case POS_RightUp:
+ x = x + mrg;
+ y = ( y - mrg ) - ht;
+ break;
+
+ case POS_LeftUp:
+ x = ( x - mrg ) - wd;
+ y = ( y - mrg ) - ht;
+ break;
+
+ case POS_RightDown:
+ x = x + mrg;
+ y = y + mrg;
+ break;
+
+ case POS_LeftDown:
+ x = ( x - mrg ) - wd;
+ y = y + mrg;
+ break;
+ }
+
+ if ( x < 0 ) {
+
+ x = ht % 16;
+ }
+ if ( x + wd >= sw ) {
+
+ x = sw - wd - ( ht % 16 );
+
+ if ( x < 0 ) {
+ if ( m_htmlPart ) m_htmlPart->view() ->setVScrollBarMode( QScrollView::AlwaysOn );
+ x = 0;
+ wd = sw;
+ }
+ }
+
+ if ( y < 0 ) {
+ if ( x <= pos.x() && pos.x() < x + wd ) {
+ if ( m_htmlPart ) m_htmlPart->view() ->setVScrollBarMode( QScrollView::AlwaysOn );
+ ht += y;
+ }
+ y = 0;
+ }
+ if ( y + ht >= sh ) {
+
+ if ( x <= pos.x() && pos.x() < x + wd ) {
+ if ( m_htmlPart ) m_htmlPart->view() ->setVScrollBarMode( QScrollView::AlwaysOn );
+ ht = sh - y;
+ } else {
+ y = sh - ht;
+
+ if ( y < 0 ) {
+ if ( m_htmlPart ) m_htmlPart->view() ->setVScrollBarMode( QScrollView::AlwaysOn );
+ y = 0;
+ ht = sh;
+ }
+ }
+ }
+
+ pos.setX( x );
+ pos.setY( y );
+ move( pos );
+
+ if ( m_htmlPart ) m_htmlPart->view() ->resize( wd, ht );
+ resize( wd , ht );
+ }
+
+
+ /* move mouse pointer above the popup frame */ /* public */
+ void ResPopup::moveMouseAbove()
+ {
+ /* config */
+
+ const int mrg = 10;
+
+ /*-------------------------------*/
+
+ QPoint pos = QCursor::pos();
+ int cx = pos.x(), cy = pos.y();
+ int px = x();
+ int py = y();
+ int wd = width();
+ int ht = height();
+
+ if ( cx <= px ) cx = px + mrg;
+ else if ( cx >= px + wd ) cx = px + wd - mrg;
+
+ if ( cy <= py ) cy = py + mrg;
+ else if ( cy >= py + ht ) cy = py + ht - mrg;
+
+ QCursor::setPos( cx, cy );
+ }
+}
--- /dev/null
+/***************************************************************************
+* Copyright (C) 2007 by Kita Developers *
+* ikemo@users.sourceforge.jp *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#ifndef RESPOPUP_H
+#define RESPOPUP_H
+
+#include <qframe.h>
+
+#include "htmlpart.h"
+
+namespace Kita
+{
+ class ResPopup : public QFrame
+ {
+ Q_OBJECT
+
+ KitaHTMLPart* m_htmlPart;
+ KURL m_url;
+
+
+ public:
+ ResPopup( KHTMLView* view, const KURL& datURL );
+ ~ResPopup();
+ void setText( const QString& str );
+ void adjustSize();
+ void adjustPos( QPoint pos );
+ void moveMouseAbove();
+
+ private:
+ void showImage( const KURL& url );
+
+ signals:
+ void hideChildPopup();
+ };
+}
+
+#endif