16 #include "msdevstudio/MSconfig.h"
31 #include <qapplication.h>
32 #include <qclipboard.h>
36 #if QT_VERSION < 0x040000
37 #include <qdragobject.h>
39 #include <qpaintdevicemetrics.h>
42 #include <q3dragobject.h>
43 #include <QtGui/QMouseEvent>
44 #include <QtGui/QPixmap>
45 #include <QtGui/QResizeEvent>
46 #include <QtGui/QPrintDialog>
48 #include <q3paintdevicemetrics.h>
53 #include <qsettings.h>
54 #include <qstatusbar.h>
79 { QPrinter::A4, QPrinter::B5, QPrinter::Letter,
80 QPrinter::Legal, QPrinter::Executive,
81 QPrinter::A0, QPrinter::A1, QPrinter::A2, QPrinter::A3,
82 QPrinter::A5, QPrinter::A6, QPrinter::A7, QPrinter::A8,
83 QPrinter::A9, QPrinter::B0, QPrinter::B1,
84 QPrinter::B10, QPrinter::B2, QPrinter::B3, QPrinter::B4,
85 QPrinter::B6, QPrinter::B7, QPrinter::B8, QPrinter::B9,
86 QPrinter::C5E, QPrinter::Comm10E,
87 QPrinter::DLE, QPrinter::Folio, QPrinter::Ledger,
88 QPrinter::Tabloid, QPrinter::Custom, QPrinter::NPageSize };
96 QPrinter::Landscape };
106 using namespace hippodraw;
113 #if QT_VERSION < 0x040000
115 const char * name, Qt::WFlags f)
119 const char * name,
Qt::WFlags f)
120 : Q3CanvasView ( c, parent, name, f ),
122 m_scale_factor ( 1.0 ),
123 m_printer_bounds ( false ),
124 m_ignore_margin ( false ),
127 m_zoom_mode = false ;
129 m_canvas = canvas ();
130 m_canvas->setUpdatePeriod ( 30 );
132 if ( s_printer == 0 )
137 calcPrinterMetrics ( s_printer );
139 m_canvas->resize ( m_apage_w, m_apage_h );
144 int pb = settings.
readNumEntry ( s_app_key +
"Canvas/Margin", 0 );
145 bool yes = ( pb == 1 ) ?
true :
false;
146 showPrinterMargins ( yes );
162 assert( pagesize < QPrinter::NPageSize );
165 const int orientation
167 QPrinter::Portrait );
168 assert( orientation == 0 || orientation == 1 );
174 assert( color == 0 || color == 1 );
212 #if QT_VERSION < 0x040000
216 iter = itemList.begin();
218 while( iter != itemList.end() )
232 Q3CanvasItemList itemList =
m_canvas -> allItems ();
234 Q3ValueListIterator< Q3CanvasItem * > iter;
235 iter = itemList.begin();
237 while( iter != itemList.end() )
239 Q3CanvasItem * item = *iter++;
244 Q3CanvasRectangle * rect
245 =
dynamic_cast< Q3CanvasRectangle *
>( item );
261 #if QT_VERSION < 0x040000
265 Q3CanvasRectangle * rect
271 rect ->moveBy ( dx, dy );
273 QColor color (
"lightGray" );
274 QPen pen ( color, 1, Qt::DashLine );
275 rect -> setPen ( pen );
291 if(
s_printer -> orientation() == QPrinter::Portrait )
308 #if QT_VERSION < 0x040000
311 Q3PaintDeviceMetrics metrics ( device );
313 int dpix = metrics.logicalDpiX ();
314 int dpiy = metrics.logicalDpiY ();
320 m_apage_h = static_cast <
int > ( m_apage_h * dpiy / 25.4 );
322 if(
s_printer -> orientation() == QPrinter::Landscape )
336 #if QT_VERSION < 0x040000
354 #if QT_VERSION < 0x040000
355 std::vector < QCanvasItem * > &
357 std::vector < Q3CanvasItem * > &
367 #if QT_VERSION < 0x040000
370 addSelectedItem ( Q3CanvasItem * item )
374 if ( ! item->isSelected() )
376 m_selected_list.push_back ( item );
384 #if QT_VERSION < 0x040000
388 vector < QCanvasItem * > ::iterator last
390 removeSelectedItem ( Q3CanvasItem * item )
392 if ( item->isSelected() ) {
393 vector < Q3CanvasItem * > ::iterator last
395 = std::remove ( m_selected_list.begin(),
396 m_selected_list.end(), item );
397 m_selected_list.erase ( last, m_selected_list.end() );
404 #ifdef ITERATOR_MEMBER_DEFECT
407 #if QT_VERSION < 0x040000
408 vector < QCanvasItem * > ::const_iterator first
412 vector < Q3CanvasItem * > ::const_iterator first
414 Q3CanvasItem * item = *first++;
416 QRect rect = item->boundingRect();
420 QRect r = item->boundingRect ();
434 #if QT_VERSION < 0x040000
435 vector < QCanvasItem * > ::const_iterator first =
m_items.begin();
436 double max_z = (*first) -> z ();
439 view =
dynamic_cast<QtView*
> (*first);
446 while ( first !=
m_items.end () ) {
449 vector < Q3CanvasItem * > ::const_iterator first =
m_items.begin();
450 double max_z = (*first) -> z ();
453 view =
dynamic_cast<QtView*
> (*first);
459 while ( first !=
m_items.end () ) {
460 Q3CanvasItem * item = *first;
462 double z = item -> z ();
465 view =
dynamic_cast<QtView*
> (item);
472 max_z = std::max ( max_z, z );
482 #if QT_VERSION < 0x040000
483 vector < QCanvasItem * > ::iterator first =
m_items.begin();
484 while ( first !=
m_items.end() ) {
487 vector < Q3CanvasItem * > ::iterator first =
m_items.begin();
488 while ( first !=
m_items.end() ) {
489 Q3CanvasItem * item = *first++;
491 if ( item->isSelected() )
continue;
492 item->setVisible ( yes );
498 #if QT_VERSION < 0x040000
501 vector < QCanvasItem * > ::iterator first =
m_items.begin ();
502 while ( first !=
m_items.end () ) {
507 vector < Q3CanvasItem * > ::iterator first =
m_items.begin ();
508 while ( first !=
m_items.end () ) {
509 Q3CanvasItem * item = *first++;
511 if ( item != target ) {
512 if ( item -> collidesWith ( target ) ) {
513 if ( item -> selected () == false ) {
514 item -> setSelected (
true );
526 #ifdef ITERATOR_MEMBER_DEFECT
529 #if QT_VERSION < 0x040000
536 Q3CanvasItem * item = *first++;
538 item->setSelected ( state );
555 #if QT_VERSION < 0x040000
556 #ifdef MEMFUN1_DEFECT
564 #ifdef MEMFUN1_DEFECT
566 bind2nd ( mem_fun1 ( &Q3CanvasItem::setSelected ), yes ) );
569 bind2nd ( mem_fun ( &Q3CanvasItem::setSelected ), yes ) );
584 #if QT_VERSION < 0x040000
591 Q3CanvasItem * item = *first++;
593 item->setSelected (
true );
603 #if QT_VERSION < 0x040000
606 const Q3CanvasItem * item = ce -> item ();
613 #if QT_VERSION < 0x040000
620 QRect rect = item->boundingRect ();
621 int x = 0, y = 0, w = 0, h = 0;
622 rect.
rect( & x, & y, & w, & h );
623 #if QT_VERSION < 0x040000
633 #if QT_VERSION < 0x040000
647 const QtView* view =
dynamic_cast<const QtView*
> (item);
649 item->setZ( z + 101.0);
651 item -> setZ ( z + 1.0 );
658 #if QT_VERSION < 0x040000
666 qApp -> postEvent (
this, event );
676 #if QT_VERSION < 0x040000
679 if ( items.empty () )
return;
682 vector < QCanvasItem * >:: const_iterator first = items.begin ();
683 while ( first != items.end () ) {
688 #ifdef MEMFUN1_DEFECT
689 for_each ( items.begin(), items.end(),
692 for_each ( items.begin(), items.end(),
700 if ( items.empty () )
return;
703 vector < Q3CanvasItem * >:: const_iterator first = items.begin ();
704 while ( first != items.end () ) {
705 Q3CanvasItem * item = *first++;
706 item->setActive ( yes );
709 #ifdef MEMFUN1_DEFECT
710 for_each ( items.begin(), items.end(),
711 bind2nd ( mem_fun1 ( &Q3CanvasItem::setActive ), yes ) );
713 for_each ( items.begin(), items.end(),
714 bind2nd ( mem_fun ( &Q3CanvasItem::setActive ), yes ) );
726 #if QT_VERSION < 0x040000
735 #if QT_VERSION < 0x040000
740 QRect rect = sel_item->boundingRect ();
742 view->
setX ( rect.
x() );
743 view->setY ( rect.
y() );
748 view->setSelected (
true );
760 #if QT_VERSION < 0x040000
761 if ( e->
state() == Qt::ShiftButton &&
762 e->
state() == Qt::ControlButton )
return;
764 if ( ( e -> modifiers () & Qt::ShiftModifier ) &&
765 ( e -> modifiers() & Qt::ControlModifier ) )
return;
769 #if QT_VERSION < 0x040000
771 QCanvasItemList::Iterator it = l.begin();
775 Q3CanvasItemList::Iterator it = l.begin();
776 Q3CanvasItem * selItem = 0;
778 for ( ; it!=l.end(); ++it) {
780 #if QT_VERSION < 0x040000
781 vector < QCanvasItem * > ::const_iterator first
783 vector < Q3CanvasItem * > ::const_iterator first
786 if ( first !=
m_items.end () ) {
796 if ( selItem == 0 ) {
799 #if QT_VERSION < 0x040000
800 if ( e->
state() != Qt::ControlButton ) {
802 if ( ( e -> modifiers() & Qt::ControlModifier ) == 0 ) {
818 if (e->
button() == Qt::LeftButton)
823 #if QT_VERSION < 0x040000
826 if (( e -> modifiers () & Qt::ShiftModifier ) &&( !
getZoomMode()))
829 if ( selItem -> isSelected () ) {
836 #if QT_VERSION < 0x040000
837 else if ( e->
state() == Qt::ControlButton )
839 else if ( e -> modifiers() & Qt::ControlModifier )
853 #if QT_VERSION < 0x040000
854 vector < QCanvasItem * > ::const_iterator first
856 vector < Q3CanvasItem * > ::const_iterator first
884 if ( e->
button() == Qt::RightButton ||
885 e->
state() == Qt::RightButton )
890 const QtView* view =
dynamic_cast<const QtView*
> (selItem);
892 selItem->setZ( z + 101.0);
894 selItem -> setZ ( z + 1.0 );
911 #if QT_VERSION < 0x040000
915 Q3CanvasRectangle * rect
916 = dynamic_cast <Q3CanvasRectangle *> (
selectedItem() );
920 int clickMargin = 10;
924 if ( ( p.
x() < rect->x() + clickMargin ) &&
925 ( p.
y() < rect->y() + clickMargin ) )
930 if ( ( p.
x() < ( rect->x() + (rect->width() / 2) + clickMargin ) ) &&
931 ( p.
x() > ( rect->x() + (rect->width() / 2) - clickMargin ) ) &&
932 ( p.
y() < rect->y() + clickMargin ) )
937 if ( ( p.
x() > ( rect->x() + rect->width() - clickMargin ) ) &&
938 ( p.
y() < rect->y() + clickMargin ) )
943 if ( ( p.
x() < rect->x() + clickMargin ) &&
944 ( p.
y() < ( rect->y() + (rect->height() / 2) + clickMargin ) ) &&
945 ( p.
y() > ( rect->y() + (rect->height() / 2) - clickMargin ) ) )
950 if ( ( p.
x() > ( rect->x() + rect->width() - clickMargin ) ) &&
951 ( p.
y() < ( rect->y() + (rect->height() / 2) + clickMargin ) ) &&
952 ( p.
y() > ( rect->y() + (rect->height() / 2) - clickMargin ) ) )
957 if ( ( p.
x() < rect->x() + clickMargin ) &&
958 ( p.
y() > rect->y() + rect->height() - clickMargin ) )
963 if ( ( p.
x() < ( rect->x() + (rect->width() / 2) + clickMargin ) ) &&
964 ( p.
x() > ( rect->x() + (rect->width() / 2) - clickMargin ) ) &&
965 ( p.
y() > rect->y() + rect->height() - clickMargin ) )
970 if ( ( p.
x() > ( rect->x() + rect->width() - clickMargin ) ) &&
971 ( p.
y() > ( rect->y() + rect->height() - clickMargin ) ) )
980 #if QT_VERSION < 0x040000
983 vector < QCanvasItem * > ::iterator last
987 vector < Q3CanvasItem * > ::iterator last
995 #if QT_VERSION < 0x040000
1007 #if QT_VERSION < 0x040000
1010 remove ( Q3CanvasItem * item )
1024 #if QT_VERSION < 0x040000
1027 hide ( Q3CanvasItem * item )
1040 #if QT_VERSION < 0x040000
1041 vector < QCanvasItem * >:: iterator it =
m_items.begin();
1043 vector < Q3CanvasItem * >:: iterator it =
m_items.begin();
1045 for ( ; it !=
m_items.end(); ++it ) {
1046 if ( *it )
delete *it;
1074 #if QT_VERSION < 0x040000
1080 Q3CanvasRectangle * rect
1081 = dynamic_cast <Q3CanvasRectangle *> ( selItem );
1093 float new_x = rect -> x();
1094 float new_y = rect -> y();
1095 float new_w = rect -> width ();
1096 float new_h = rect -> height ();
1117 new_w = new_h * aspect;
1119 new_w = std::max ( new_w, 20.0f );
1120 new_h = std::max ( new_h, 20.0f );
1122 if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1123 if (gv) gv -> setDrawRect ( new_x, new_y, new_w, new_h );
1125 rect->setEnabled (
true );
1136 new_w += aspect * d_y;
1137 new_x -= 0.5 * aspect * d_y;
1140 new_w = std::max ( new_w, 20.0f );
1141 new_h = std::max ( new_h, 20.0f );
1143 if (view) view -> setDrawRect ( new_x, p_y, new_w, new_h );
1144 if (gv) gv -> setDrawRect ( new_x, p_y, new_w, new_h );
1146 rect->setEnabled (
true );
1157 new_w = aspect * new_h;
1160 new_w = std::max ( new_w, 20.0f );
1161 new_h = std::max ( new_h, 20.0f );
1163 if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1164 if (gv) gv->setDrawRect ( new_x, new_y, new_w, new_h );
1166 rect->setEnabled (
true );
1177 new_h += d_x / aspect;
1178 new_w = new_h * aspect;
1181 new_w = std::max ( new_w, 20.0f );
1182 new_h = std::max ( new_h, 20.0f );
1184 if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1185 if (gv) gv -> setDrawRect ( new_x, new_y, new_w, new_h );
1187 rect->setEnabled (
true );
1198 new_h -= d_x / aspect;
1199 new_w = new_h * aspect;
1202 new_w = std::max ( new_w, 20.0f );
1203 new_h = std::max ( new_h, 20.0f );
1205 if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1206 if (gv) gv -> setDrawRect ( new_x, new_y, new_w, new_h );
1208 rect->setEnabled (
true );
1221 new_w = new_h * aspect;
1224 new_w = std::max ( new_w, 20.0f );
1225 new_h = std::max ( new_h, 20.0f );
1227 if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1228 if (gv) gv -> setDrawRect ( new_x, new_y, new_w, new_h );
1230 rect->setEnabled (
true );
1241 new_w = new_h * aspect;
1242 new_x += 0.5 * aspect * d_y;
1244 new_w = std::max ( new_w, 20.0f );
1245 new_h = std::max ( new_h, 20.0f );
1247 if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1248 if (gv) gv -> setDrawRect ( new_x, new_y, new_w, new_h );
1250 rect->setEnabled (
true );
1262 new_w = aspect * new_h;
1265 new_w = std::max ( new_w, 20.0f );
1266 new_h = std::max ( new_h, 20.0f );
1268 if (view) view -> setDrawRect ( new_x, new_y, new_w, new_h );
1269 if (gv) gv -> setDrawRect ( new_x, new_y, new_w, new_h );
1271 rect->setEnabled (
true );
1309 #if QT_VERSION < 0x040000
1331 if ( item -> x () < margin_x ) item -> setX ( margin_x + 1 );
1332 if ( item -> y () < margin_y ) item -> setY ( margin_y + 1 );
1334 if (
m_items.empty () )
return;
1336 double deltax = 1.05 * item -> width ();
1337 double deltay = 1.05 * item -> height ();
1341 QRect brect = item->boundingRect ();
1347 item->setY ( new_y );
1351 #if QT_VERSION < 0x040000
1352 vector < QCanvasItem * >:: iterator it =
m_items.begin();
1354 vector < Q3CanvasItem * >:: iterator it =
m_items.begin();
1356 bool collides =
false;
1358 for ( ; it !=
m_items.end(); ++it ) {
1359 if ( (*it)->collidesWith ( item ) ) {
1365 if ( !collides )
break;
1366 if ( item -> x() + deltax + item -> width () < max_width ) {
1367 item -> moveBy ( deltax, 0 );
1370 item -> setX ( margin_x + 1 );
1371 item -> moveBy ( 0, deltay );
1380 #if QT_VERSION < 0x040000
1383 add ( Q3CanvasItem * item )
1390 item->setSelected (
false );
1393 QRect area = item -> boundingRect ();
1402 #if QT_VERSION < 0x040000
1405 paste ( Q3CanvasItem * item )
1409 #if QT_VERSION < 0x040000
1412 Q3CanvasItemList items = item->collisions (
true );
1414 unsigned int count = items.count ();
1417 item->moveBy ( 10., 10. );
1423 #if QT_VERSION < 0x040000
1429 QRect brect = item->boundingRect ();
1451 resizeContents (
m_apage_w, m_apage_h );
1466 #if QT_VERSION < 0x040000
1471 matrix.scale( 4./3., 4./3. );
1483 #if QT_VERSION < 0x040000
1488 matrix.scale( 3./4., 3./4. );
1497 #if QT_VERSION < 0x040000
1514 QPrinter::PageSize page_size =
s_printer -> pageSize ();
1523 #if QT_VERSION < 0x040000
1527 QPrintDialog dialog (
s_printer,
this );
1528 bool yes = ( dialog.exec () == QDialog::Accepted );
1544 if ( yes ==
false )
return;
1554 const QString name = filename.c_str();
1555 s_printer -> setOutputFileName ( name );
1567 bool ok = painter.
begin ( printer );
1572 painter.
scale ( scale, scale );
1576 while ( page_y < m_canvas->height() ) {
1578 #if QT_VERSION < 0x040000
1584 if ( items.empty () ) {
1590 if ( page_y != 0 ) printer->
newPage();
1615 updateScrollBars ();
1626 updateScrollBars ();
1646 painter.
begin ( pixmap );
1647 painter.translate ( -rect.
x(), -rect.
y() );
1660 QString fn ( filename.c_str() );
1661 string::size_type i = filename.find_last_of (
'.' );
1662 string suffix ( filename.substr ( i + 1 ) );
1663 transform ( suffix.begin(), suffix.end(),
1664 suffix.begin(), toupper );
1665 if ( suffix ==
"JPG" ) suffix =
"JPEG";
1667 pixmap -> save ( fn, suffix.c_str() );
1677 QImage image = pixmap -> convertToImage ();
1688 #if QT_VERSION < 0x040000
1691 Q3ImageDrag * image_drag =
new Q3ImageDrag ( image );
1694 cb -> setData ( image_drag );
1706 QWidget * view_port = viewport ();
1707 view_port -> setMouseTracking ( TRUE );
1711 QWidget * view_port = viewport ();
1712 view_port -> setMouseTracking ( FALSE );
1753 #if QT_VERSION < 0x040000
1771 #if QT_VERSION < 0x040000
1789 #if QT_VERSION < 0X040000
1796 #if QT_VERSION < 0x040000
1798 QCanvasItemList::Iterator it = item_list.begin();
1801 Q3CanvasItemList::Iterator it = item_list.begin();
1808 item->moveBy(dx,dy);
1811 for ( ; it !=item_list.end(); ++it ) {
1812 const QtView * view = dynamic_cast <
const QtView * > ( *it);
1816 (*it)->moveBy(dx,dy);