📄 globjwin.c
字号:
/****************************************************************************** $Id: globjwin.cpp,v 1.6 1999/01/22 08:01:00 aavit Exp $**** ImPlementation of GLObjectWindow widget class******************************************************************************/#include <stdio.h>#include <qpushbutton.h>#include <qslider.h>#include <qlayout.h>#include <qframe.h>#include <qmenubar.h>#include <qpopupmenu.h>#include <qapplication.h>#include <qkeycode.h>#include <qnamespace.h>#include <qfiledialog.h>#include <math.h>#include <ctype.h>#include <time.h>#include <stdlib.h>#include <assert.h>#include "_generic.h"#include "sarray.h"#include "real.h"#include "point.h"//#include "glwindow.h"#include "glbox.h"#include "globjwin.h"#include "glbox.h"static bool is_exist( char * filename ) { FILE * fl; fl = fopen( filename, "rt" ); if ( fl == NULL ) return false; fclose( fl ); return true;}void GLObjectWindow::write_status( char * filename ){ FILE * fl; if ( is_exist( filename ) ) { printf( "can not rewrite file: [%s]\n", filename ); return; } fl = fopen( filename, "wt" ); if ( fl == NULL ) { printf( "Unable to open file; [%s]\n", filename ); return; } fclose( fl );}void GLObjectWindow::read_status( char * filename ){ FILE * fl; fl = fopen( filename, "rt" ); if ( fl == NULL ) { printf( "Unable to open file; [%s]\n", filename ); return; } fclose( fl ); object_win->setUpdateGL( false ); object_win->resetDisplay(); //object_win->setUpdateGL( true ); //object_win->myUpdateGL();}void GLObjectWindow::keyPressEvent( QKeyEvent *k ){ switch ( k->key() ) { case Key_F1 : write_status( "status.txt" ); return; case Key_F2 : read_status( "status.txt" ); return; }; switch ( k->ascii() ) { case 27: // quit exit( 0 ); break; default: //object_win->keyPressEvent( k ); break; }}QMenuBar * GLObjectWindow::compute_menu( GLObjectWindow * ptr ){ // Create a menu QPopupMenu *file = new QPopupMenu(); CHECK_PTR( file ); file->insertItem( "E&xit", qApp, SLOT(quit()), Qt::CTRL + Qt::Key_Q ); // Create a menu bar QMenuBar *m = new QMenuBar( ptr ); m->setSeparator( QMenuBar::InWindowsStyle ); m->insertItem("&File", file ); return m;}void GLObjectWindow::btnLoadClicked(){ QString fileName = QFileDialog::getOpenFileName(); if ( fileName.isNull() ) return; object_win->load( (const char *)fileName );}void GLObjectWindow::btnDiameterClicked(){ object_win->comp_diameter();}QPushButton * addButton( QWidget * top, char * str, char * id_str, QBoxLayout * layout ){ QPushButton * qb = new QPushButton( top, id_str ); qb->setText( str ); qb->setFixedHeight( qb->sizeHint().height() ); //layout->addStretch( 1 ); layout->addWidget( qb, 100 ); //, 0, AlignLeft ); return qb;}GLObjectWindow::GLObjectWindow( QWidget* parent, const char* name, Terrain * tr ) : QWidget( parent, name ){ QMenuBar * menu; menu = compute_menu( this ); QBoxLayout* vlayout_main = new QVBoxLayout( this, 20, 20, "vlayout_main"); //QHBoxLayout* hlayout = new QHBoxLayout(); vlayout_main->setMenuBar( menu ); setMinimumSize( 700, 500 ); // Create a nice frame to put around the OpenGL widget QFrame* frame = new QFrame( this, "frame" ); frame->setFrameStyle( QFrame::Sunken | QFrame::Panel ); frame->setLineWidth( 2 ); // Create our OpenGL widget GLBox* gl_window = new GLBox( frame, "glbox" ); object_win = gl_window; //gl_window->setMinimumWidth( 100 ); //gl_window->setMinimumHeight( 100 ); //QVBoxLayout* vlayout = new QVBoxLayout( this, 0, 20, "vlayout"); // Create the three sliders; one for each rotation axis //QVBoxLayout* vlayout = new QVBoxLayout();//this, 0, 20, "vlayout"); // Put the GL widget inside the frame QHBoxLayout* flayout = new QHBoxLayout( frame, 2, 2, "flayout"); flayout->addWidget( gl_window, 10 ); // Top level layout, puts the sliders to the left of the frame/GL widget //hlayout->addLayout( vlayout ); //hlayout->addWidget( frame, 1 ); // Put the sliders on top of each other //printf( "1\n" ); //printf( "2\n" ); //printf( "3\n" ); // Translation //QVBoxLayout* trans_layout = new QVBoxLayout( 20, "vlayout"); //QVAaBoxLayout* vlayout_main = new QVBoxLayout( this, 20, 20, "vlayout_main"); //printf( "x2x\n" ); //vlayout->addWidget( x ); //vlayout->addWidget( y ); //vlayout->addWidget( z ); //vlayout_main->addLayout( hlayout ); vlayout_main->addWidget( frame ); //-------------------------------------------------------------- // Buttons //-------------------------------------------------------------- QHBoxLayout * btn_layout = new QHBoxLayout(); pbLoad = addButton( this, "Load", "LoadButton", btn_layout ); connect( pbLoad, SIGNAL(clicked()), SLOT( btnLoadClicked() ) ); pbDiam = addButton( this, "Diameter", "LoadButton", btn_layout ); connect( pbDiam, SIGNAL(clicked()), SLOT( btnDiameterClicked() ) ); vlayout_main->addLayout( btn_layout ); // Create a menu //printf( "x1x\n" );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -