| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: secret.cpp 160 2006-12-11 20:15:57Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Custom MIME type implementation example
|
|---|
| 5 | **
|
|---|
| 6 | ** Created : 979899
|
|---|
| 7 | **
|
|---|
| 8 | ** Copyright (C) 1997 by Trolltech AS. All rights reserved.
|
|---|
| 9 | **
|
|---|
| 10 | ** This file is part of an example program for Qt. This example
|
|---|
| 11 | ** program may be used, distributed and modified without limitation.
|
|---|
| 12 | **
|
|---|
| 13 | *****************************************************************************/
|
|---|
| 14 |
|
|---|
| 15 | #include "secret.h"
|
|---|
| 16 | #include <qevent.h>
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 | //create the object withe the secret byte
|
|---|
| 20 | SecretDrag::SecretDrag( uchar secret, QWidget * parent, const char * name )
|
|---|
| 21 | : QStoredDrag( "secret/magic", parent, name )
|
|---|
| 22 | {
|
|---|
| 23 | QByteArray data(1);
|
|---|
| 24 | data[0]= secret;
|
|---|
| 25 | setEncodedData( data );
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 | bool SecretDrag::canDecode( QDragMoveEvent* e )
|
|---|
| 30 | {
|
|---|
| 31 | return e->provides( "secret/magic" );
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | //decode it into a string
|
|---|
| 35 | bool SecretDrag::decode( QDropEvent* e, QString& str )
|
|---|
| 36 | {
|
|---|
| 37 | QByteArray payload = e->data( "secret/magic" );
|
|---|
| 38 | if ( payload.size() ) {
|
|---|
| 39 | e->accept();
|
|---|
| 40 | QString msg;
|
|---|
| 41 | msg.sprintf("The secret number is %d", payload[0] );
|
|---|
| 42 | str = msg;
|
|---|
| 43 | return TRUE;
|
|---|
| 44 | }
|
|---|
| 45 | return FALSE;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | SecretSource::SecretSource( int secret, QWidget *parent, const char * name )
|
|---|
| 50 | : QLabel( "Secret", parent, name )
|
|---|
| 51 | {
|
|---|
| 52 | setBackgroundColor( blue.light() );
|
|---|
| 53 | setFrameStyle( Box | Sunken );
|
|---|
| 54 | setMinimumHeight( sizeHint().height()*2 );
|
|---|
| 55 | setAlignment( AlignCenter );
|
|---|
| 56 | mySecret = secret;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | SecretSource::~SecretSource()
|
|---|
| 60 | {
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | /* XPM */
|
|---|
| 64 | static const char * picture_xpm[] = {
|
|---|
| 65 | "16 16 3 1",
|
|---|
| 66 | " c None",
|
|---|
| 67 | ". c #000000",
|
|---|
| 68 | "X c #FFFF00",
|
|---|
| 69 | " ..... ",
|
|---|
| 70 | " ..XXXXX.. ",
|
|---|
| 71 | " .XXXXXXXXX. ",
|
|---|
| 72 | " .XXXXXXXXXXX. ",
|
|---|
| 73 | " .XX..XXX..XX. ",
|
|---|
| 74 | ".XXXXXXXXXXXXX. ",
|
|---|
| 75 | ".XX...XXX...XX. ",
|
|---|
| 76 | ".XXX..XXX..XXX. ",
|
|---|
| 77 | ".XXXXXXXXXXXXX. ",
|
|---|
| 78 | ".XXXXXX.XXXXXX. ",
|
|---|
| 79 | " .XX.XX.XX.XX. ",
|
|---|
| 80 | " .XXX..X..XXX. ",
|
|---|
| 81 | " .XXXXXXXXX. ",
|
|---|
| 82 | " ..XXXXX.. ",
|
|---|
| 83 | " ..... ",
|
|---|
| 84 | " "};
|
|---|
| 85 |
|
|---|
| 86 | void SecretSource::mousePressEvent( QMouseEvent * /*e*/ )
|
|---|
| 87 | {
|
|---|
| 88 | SecretDrag *sd = new SecretDrag( mySecret, this );
|
|---|
| 89 | sd->setPixmap(QPixmap(picture_xpm),QPoint(8,8));
|
|---|
| 90 | sd->dragCopy();
|
|---|
| 91 | mySecret++;
|
|---|
| 92 | }
|
|---|